roslyn: MEF and Workspaces crash with ReflectionTypeLoadException on Mono
Version Used: 2.2.0
Steps to Reproduce:
- Create a new console app in Visual Studio for Mac Beta (7.0.1 b24, but it doesn’t really matter, this bug is ancient)
- Reference Microsoft.CodeAnalysis 2.2.0 (again, version doesn’t matter)
- Add this line:
var workspace = MSBuildWorkspace.Create();
- Run the code
Expected Behavior: A new workspace object is created
Actual Behavior: Crash!
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
When I first talked about this bug on Twitter years ago, a mono community member knew what the issue was - something about loading rules for assemblies. Unfortunately, I cannot remember the details and twitter search is failing me.
I worked around this bug for years by simply not using the Workspace feature. It’s been hard. I would love to have this working.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 28 (22 by maintainers)
It looks like a layering violation was introduced awhile back with https://github.com/dotnet/roslyn/pull/14055 when a reference to
Microsoft.VisualStudio.RemoteControl
toMicrosoft.CodeAnalysis.Workspaces.Desktop
. This was removed with https://github.com/dotnet/roslyn/commit/b104fbf4dd6d0fe86942029f2044b43ef2db62af.Note: @Pilchie, this dependency was moved to the editor layer, but I’m not sure that’s the right place yet. If
Microsoft.VisualStudio.RemoteControl
is a VS dependency, it should be factored into the VS layer.Well, originally, this project was created for MSBuildWorkspace. Since it’s a public API, moving it would be a breaking change.
Yes, VSM wrote it’s own. MSBuildWorkspace has very limited support for modifying things/hosting in an editor/etc. It’s mostly there for writing static analysis type tools.
Note that @mhutch uses MEF in VS4Mac on Mono, and @DustinCampbell does for Omnisharp-roslyn so I don’t think that’s it. This may be something specific to
MSBuildWorkspace
.