Bug 57568 - System.Reflection.Assembly.DefinedTypes throws ReflectionTypeLoadException when using MEF
Summary: System.Reflection.Assembly.DefinedTypes throws ReflectionTypeLoadException wh...
Status: RESOLVED ANSWERED
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: 5.0 (2017-02)
Hardware: Macintosh Mac OS
: --- major
Target Milestone: Future Cycle (TBD)
Assignee: Aleksey Kliger
URL:
Depends on:
Blocks:
 
Reported: 2017-06-16 19:49 UTC by Frank A. Krueger
Modified: 2017-07-07 15:54 UTC (History)
4 users (show)

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


Attachments
Project demonstrating the bug (5.81 KB, application/zip)
2017-06-16 19:49 UTC, Frank A. Krueger
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 GitHub or Developer Community 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:
RESOLVED ANSWERED

Description Frank A. Krueger 2017-06-16 19:49:52 UTC
Created attachment 22956 [details]
Project demonstrating the bug

Original bug filed against Roslyn: https://github.com/dotnet/roslyn/issues/20275#issuecomment-309116815

Repro:

1. Load the attached TestRoslyn solution
2. Restore all the packages
3. Run

Expected: Workspace object is created

Actual:

System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Reflection/Assembly.cs:410 
  at System.Reflection.Assembly+<get_DefinedTypes>d__150.MoveNext () [0x0001e] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Reflection/Assembly.cs:1019 
  at System.Linq.Enumerable+SelectEnumerableIterator`2[TSource,TResult].MoveNext () [0x00029] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq/src/System/Linq/Select.cs:133 
  at System.Linq.Enumerable+SelectManySingleSelectorIterator`2[TSource,TResult].MoveNext () [0x0006f] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq/src/System/Linq/SelectMany.cs:209 
  at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor (System.Collections.Generic.IEnumerable`1[T] types, System.Composition.Convention.AttributedModelProvider attributeContext) [0x00049] in <c091afde214c4b8e8efbbeb9d44062d4>:0 
  at System.Composition.Hosting.ContainerConfiguration.CreateContainer () [0x00042] in <c091afde214c4b8e8efbbeb9d44062d4>:0 
  at Microsoft.CodeAnalysis.Host.Mef.MefHostServices.Create (System.Collections.Generic.IEnumerable`1[T] assemblies) [0x0001e] in <7f0d4b9d7a9a40cfa302b8c61f11defa>:0 
  at Microsoft.CodeAnalysis.Host.Mef.DesktopMefHostServices.get_DefaultServices () [0x00011] in <43494904657a4fb99e35e930a2c70ef9>:0 
  at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create (System.Collections.Generic.IDictionary`2[TKey,TValue] properties) [0x00000] in <43494904657a4fb99e35e930a2c70ef9>:0 
  at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create () [0x00000] in <43494904657a4fb99e35e930a2c70ef9>:0 
  at TestRoslyn.MainClass.Main (System.String[] args) [0x00001] in /Users/fak/Projects/TestRoslyn/Program.cs:11 

Mono JIT compiler version 5.0.1.1 (2017-02/5077205 Thu May 18 16:11:37 EDT 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          yes(3.6.0svn-mono-master/8b1520c)
	GC:            sgen (concurrent by default)
Comment 1 Zoltan Varga 2017-06-19 18:45:33 UTC
Running with MONO_LOG_LEVEL=debug prints this:

Mono: The following assembly referenced from /Users/vargaz/Projects/57568/TestRoslyn/bin/Debug/Microsoft.CodeAnalysis.Workspaces.Desktop.dll could not be loaded:
     Assembly:   Microsoft.Build.Tasks.Core    (assemblyref_index=9)
     Version:    15.1.0.0
     Public Key: b03f5f7f11d50a3a
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/Users/vargaz/Projects/57568/TestRoslyn/bin/Debug/).
Comment 2 Ludovic Henry 2017-07-05 19:10:15 UTC
Aleksey, could you please take a look at that? It seems to be a missing library from the GAC. Thank you!
Comment 3 Aleksey Kliger 2017-07-05 19:32:04 UTC
The version I see in the GAC is 14.0.0.0__b03f5f7f11d50a3a the key is right, but the version is wrong.  There's either a missing .config file with a version remap, or we're not reading one somehow.  Does this project work under .NETFramework?
Comment 4 Aleksey Kliger 2017-07-07 15:54:43 UTC
https://github.com/dotnet/roslyn/issues/20275#issuecomment-312103760

This seems like a combination of a packaging issue for Microsoft.CodeAnalysis (missing package references to Microsoft.Build and Microsoft.Build.Tasks.Core) and the fact that  Microsoft.CodeAnalysis.Workspaces.Desktop references Microsoft.VisualStudio.RemoteControl which is not supported by Mono.

Please reopen or file a new bug if there's anything to be done on the Mono side in the future or if I misunderstood the situation.