Bug 55988 - Apps using Roslyn crash when trying to load Roslyn
Summary: Apps using Roslyn crash when trying to load Roslyn
Status: VERIFIED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Runtime ()
Version: 3.4.0 (15.2)
Hardware: PC Mac OS
: High major
Target Milestone: 15.2.2
Assignee: Ankit Jain
URL:
Depends on:
Blocks:
 
Reported: 2017-05-04 17:44 UTC by Bojan Rajkovic [MSFT]
Modified: 2017-05-22 20:55 UTC (History)
9 users (show)

Tags:
Is this bug a regression?: Yes
Last known good build: 15.1


Attachments
Console and Mac projects (351.78 KB, application/zip)
2017-05-04 17:44 UTC, Bojan Rajkovic [MSFT]
Details
Trace from running Mac app w/ MONO_LOG_MASK=asm MONO_LOG_LEVEL=debug (71.93 KB, text/plain)
2017-05-04 17:44 UTC, Bojan Rajkovic [MSFT]
Details
Trace from running Console app w/ MONO_LOG_MASK=asm MONO_LOG_LEVEL=debug (14.47 KB, text/plain)
2017-05-04 17:45 UTC, Bojan Rajkovic [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Bojan Rajkovic [MSFT] 2017-05-04 17:44:32 UTC
Created attachment 21953 [details]
Console and Mac projects

Apps that use Roslyn crash when trying to actually load the Microsoft.CodeAnalysis.CSharp assembly. 
The reason appears to be that it wants to use System.ValueTuple, and loading *that* assembly is denied by the underlying Mono.

Console apps on the same Mono do not exhibit this problem—the "bad" SVT DLL is attempted (from the NuGet), and then the Facade from the framework is loaded instead, and things work.

Attached is a sample project and the output of `MONO_LOG_MASK=asm MONO_LOG_DLL=debug` runs of both the Mac app and the console app.
Comment 1 Bojan Rajkovic [MSFT] 2017-05-04 17:44:57 UTC
Created attachment 21954 [details]
Trace from running Mac app w/ MONO_LOG_MASK=asm MONO_LOG_LEVEL=debug
Comment 2 Bojan Rajkovic [MSFT] 2017-05-04 17:45:12 UTC
Created attachment 21955 [details]
Trace from running Console app w/ MONO_LOG_MASK=asm MONO_LOG_LEVEL=debug
Comment 3 Bojan Rajkovic [MSFT] 2017-05-04 17:57:05 UTC
Copying the correct facades in by hand from X.M fixes the issue:

`cp /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/Facades/System.ValueTuple.dll ./TestRoslynApp/bin/Debug/Test\ Roslyn\ App.app/Contents/MonoBundle/`
`cp /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/Facades/System.Text.Encoding.CodePages.dll ./TestRoslynApp/bin/Debug/Test\ Roslyn\ App.app/Contents/MonoBundle/`

After that, the app runs fine.
Comment 4 Chris Hamons 2017-05-04 22:50:13 UTC
Here is an analysis of the issue -https://gist.github.com/chamons/3ad1634b2d453458c096382a77970f2b

And here is a totally hack of a possible solution - https://gist.github.com/chamons/579b408517a4546a5b2c98790ec2777f

@Marek is digging into the correction solution.
Comment 5 Chris Hamons 2017-05-04 22:51:40 UTC
This may not make 15.2, but it is blocking Workbooks from using 15.2.
Comment 6 Chris Hamons 2017-05-04 22:55:59 UTC
15.2 is too late. We'll backport it on 15.2 for workbooks if needed later.
Comment 7 Marek Safar 2017-05-05 12:10:49 UTC
I think we need some runtime support for this because linker or mkbundle could fell into same trap.
Comment 8 Rodrigo Kumpera 2017-05-05 18:01:58 UTC
What do we need to do?
Comment 10 Marek Safar 2017-05-11 17:32:40 UTC
We'll try to fix it at build level which seems to me is the most general solution. I asked Ankit to work/protype the approach where msbuild checks assemblies which are copied into output folder and if one of them is blacklisted then it needs to copy it at all. I think this should cover XM case too but if not we just add extra copy step.

Ankit, we have a tool [0] to a build a list of these assemblies and we try to work with CoreFX folks to not expand it but what's there right now will stay there.

[0] https://github.com/mono/mono/tree/master/tools/nuget-hash-extractor
Comment 14 Marek Safar 2017-05-13 08:27:48 UTC
I just realised for the System.ValueTuple.dll special case we can just disable the remapping in the runtime, if XM correctly uses reference assemblies we'll have to do it anyway as the Mono version of System.ValueTuple won't be available.
Comment 15 Marek Safar 2017-05-13 08:44:27 UTC
Mono PR https://github.com/mono/mono/pull/4858
Comment 17 GouriKumari 2017-05-17 16:43:52 UTC
Verified with XM 3.4.0.44 and mono 5.0.0.112. Issue with System.Value.Tuple got resolved. But the test app is throwing an error that it can't load System.Text.Encoding.CodePages'. 

## Logs:
Build Log: https://gist.githubusercontent.com/GouriKumari/b570bef07f6b913c9ff10df13fc57d56/raw/9f8df4fb26cc8c3e30f3c5b6796a1632a3abb492/gistfile1.txt

Error Log: https://gist.github.com/GouriKumari/5c0b3d89a23891fb03f9960bea8c3e96

## Test Env:
https://gist.github.com/24554801aee0b26a2270d250fd67afb7
Comment 18 GouriKumari 2017-05-17 18:05:22 UTC
Since, the initial issue mentioned in the bug is verified fixed, I am closing this bug. Filed a new one for the issue mentioned in comment#17 : https://bugzilla.xamarin.com/show_bug.cgi?id=56574
Comment 19 Alok Kulkarni 2017-05-19 13:15:42 UTC
I am trying to reproduce the original defect[ Issue with System.Value.Tuple ] on my side but, any quick help regarding steps will be beneficial.
Comment 20 GouriKumari 2017-05-22 20:55:55 UTC
Verified with XM 3.4.0.36.pkg and the issue is resolved. Rosyln app launches without any exception.

##Logs:
Build Log: https://gist.githubusercontent.com/GouriKumari/d47d35a6832c5323ecc9ddd3db0b535d/raw/6f0b39b4d325173e26969ce52d9ccf751952022a/gistfile1.txt

## Test Env:
https://gist.github.com/2bd8651e2285eb98b15761f46d90e6fe