Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

When using XAML compilation, StackOverflowException is raised in XamlCTask if the conditions are just right #2550

Open
ptsoccer opened this issue Apr 26, 2018 · 3 comments
Assignees
Labels
a/Xaml </> e/5 🕔 5 help wanted We welcome community contributions to any issue, but these might be a good place to start! i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!

Comments

@ptsoccer
Copy link

Description

In a particular certain set of circumstances, the XamlCTask will error in a stack overflow in which the mono cecil library ping pongs between mscorlib and netstandard looking for System.Type.

The steps are pretty convoluted, my attached file is setup the way it needs to be.
The environment needed for the exception to occur is:

  1. All binaries must be built to the same directory
  2. The netstandard.dll forwarding assembly must already be in the output folder (this comes from a .net framework project referencing a .net standard dll)
  3. The xamarin forms project must reference a project that is first on the primary reference list for the xamarin forms project (usually accomplished by giving the reference a name that starts with a,b,c or something)
  4. XAML compilation must be turned on in a view (need this for XamlCTask to resolve references and emite il).

With this setup, when XamlCTask executes it:

  1. Splits the ReferencePath and adds each directory to the search path. Because the referenced project starts with a,b,c the first directory on the search path is the output folder.
  2. Because XAML compilation is turned on, TryCoreCompile imports System.Type from mscorlib. XamlCAssemblyResolver finds this dll in the netstandard.library nuget package. This is a forwarding assembly that forwards to netstandard.dll.
  3. Mono cecil then attempts to resolve System.Type in netstandard.dll. Because the netstandard.dll is already in the output folder and the output folder is first in the search directories, XamlCAssemblyResolver resolves netstandard.dll to the one in the output folder. This is a problem, however, because that dll is a forwarding assembly that forwards to mscorlib.dll.
  4. Mono cecil now tries to resolve System.Type in mscorlib.dll, and thus the stack overflow happens.

For this to not have happened, netstandard.dll should have been loaded from the netstandard.library nuget package. I believe this can be done by preferring to load the requested dlls in the ReferencePath property first, and if it doesn't find it there, look in the search directories in the XamlCAssemblyResolver class.

Steps to Reproduce

  1. Download reproduction
  2. Open a VS 2017 developer command prompt
  3. Run the following msbuild command, be sure to specify the path to the solution file, and also be sure to specify the path to the solution directory for the OutputPath:

MSBuild.exe "<Path to XamarinStaticBinding.sln>" /p:OutputPath="<Path to solution folder>\Output" /restore /p:Configuration="Release" /p:Platform="Any CPU" /verbosity:minimal

Expected Behavior

Compile succeeds

Actual Behavior

MSBuild crashes with a StackOverflowException

Basic Information

  • Version with issue: 3.0-pre4

Reproduction Link

XamarinStaticBinding.zip

@StephaneDelcroix StephaneDelcroix self-assigned this Apr 30, 2018
@samhouts samhouts added the e/5 🕔 5 label Oct 16, 2018
@samhouts samhouts added the inactive Issue is older than 6 months and needs to be retested label Dec 20, 2018
@samhouts samhouts added the i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often label May 29, 2019
@samhouts samhouts added help-wanted up-for-grabs We welcome community contributions to any issue, but these might be a good place to start! help wanted We welcome community contributions to any issue, but these might be a good place to start! and removed help-wanted labels Jun 28, 2019
@samhouts
Copy link
Member

samhouts commented Aug 7, 2020

This issue doesn't seem to have had any activity in a long time. We're working on prioritizing issues and resolving them as quickly as we can. To help us get through the list, we would appreciate an update from you to let us know if this is still affecting you on the latest version of Xamarin.Forms, since it's possible that we may have resolved this as part of another related or duplicate issue. If we don't see any new activity on this issue in the next 30 days, we'll evaluate whether this issue should be closed. Thank you!

@samhouts samhouts added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Aug 7, 2020
@ptsoccer
Copy link
Author

ptsoccer commented Aug 7, 2020

I just tried with version 4.8.0.1269 and it's still an issue

@PureWeen
Copy link
Contributor

PureWeen commented Aug 8, 2020

@StephaneDelcroix FYI

@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@samhouts samhouts removed inactive Issue is older than 6 months and needs to be retested s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. labels Sep 15, 2020
@samhouts samhouts removed this from the 5.0.0 milestone Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/Xaml </> e/5 🕔 5 help wanted We welcome community contributions to any issue, but these might be a good place to start! i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Projects
None yet
Development

No branches or pull requests

4 participants