Bug 60783 - TypeLoadException:Parent class failed to load, due to: Could not load list of method overrides assembly
Summary: TypeLoadException:Parent class failed to load, due to: Could not load list of...
Status: RESOLVED ANSWERED
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: 5.8 (2017-10)
Hardware: PC Mac OS
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Aleksey Kliger
URL:
Depends on:
Blocks:
 
Reported: 2017-11-21 01:36 UTC by Kirill Osenkov
Modified: 2017-11-29 22:38 UTC (History)
5 users (show)

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

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 Kirill Osenkov 2017-11-21 01:36:00 UTC
TypeLoadException: Parent class failed to load, due to: Could not load list of method overrides assembly:/Users/kirill/MonoRepro/CantLoadType/CantLoadType/bin/Debug/Microsoft.CodeAnalysis.EditorFeatures.dll type:SuggestedAction member:<none>

Repro:
1. git clone https://github.com/KirillOsenkov/MonoRepro
2. Open ~/MonoRepro/CantLoadType/CantLoadType.sln and run

Expected: works fine on Windows

Actual:
Unhandled Exception:
System.TypeLoadException: Parent class failed to load, due to: Could not load list of method overrides assembly:/Users/kirill/MonoRepro/CantLoadType/CantLoadType/bin/Debug/Microsoft.CodeAnalysis.EditorFeatures.dll type:SuggestedAction member:<none>
  at (wrapper managed-to-native) System.RuntimeType.GetPropertiesByName_native(System.RuntimeType,intptr,System.Reflection.BindingFlags,bool)
  at System.RuntimeType.GetPropertiesByName (System.String name, System.Reflection.BindingFlags bindingAttr, System.Boolean icase, System.RuntimeType reflectedType) [0x0001b] in <4656b2b94f914437bce672312dd9e44b>:0 
  at System.RuntimeType.GetPropertyCandidates (System.String name, System.Reflection.BindingFlags bindingAttr, System.Type[] types, System.Boolean allowPrefixLookup) [0x00010] in <4656b2b94f914437bce672312dd9e44b>:0 
  at System.RuntimeType.GetProperties (System.Reflection.BindingFlags bindingAttr) [0x00000] in <4656b2b94f914437bce672312dd9e44b>:0 
  at System.Type.GetProperties () [0x00000] in <4656b2b94f914437bce672312dd9e44b>:0 
  at CantLoadType.MainClass.Reflect (System.Type type) [0x00002] in <45034b6cbe1045c0841d345de8769b94>:0 
  at CantLoadType.MainClass.Main (System.String[] args) [0x00020] in <45034b6cbe1045c0841d345de8769b94>:0 

All the assemblies in question are checked in under /CantLoadType/CantLoadType/lib

The "root" assembly is Microsoft.CodeAnalysis.EditorFeatures.dll.

The weirdness starts around the type SuggestedAction:
http://source.roslyn.io/#Microsoft.CodeAnalysis.EditorFeatures/Implementation/Suggestions/SuggestedActions/SuggestedAction.cs,72ee6a717bc09afb
Comment 1 Ludovic Henry 2017-11-21 18:55:29 UTC
I can reproduce with Mono 5.8.0.70 (2017-10/efce3b256a5).

To reproduce, run:

> git clone https://github.com/KirillOsenkov/MonoRepro
> cd MonoRepro
> msbuild /t:Build CantLoadType/CantLoadType.sln
> msbuild /t:Run CantLoadType/CantLoadType.sln
Comment 2 Aleksey Kliger 2017-11-21 19:25:22 UTC
This is a good opportunity to rewrite mono_class_get_overrides_full not to swallow the MonoError messages.
Comment 3 Aleksey Kliger 2017-11-21 22:20:14 UTC
This is happening because ImageMoniker is defined by multiple assemblies: Microsoft.CodeAnalysis.EditorFeatures.dll and Microsoft.VisualStudio.Language.Intellisense.dll which are then identified using type equivalence (TypeIdentifierAttribute).

Embedded interop types / type equivalence is not supported by Mono and would require a lot of work to add.

Details:
  SuggestedAction provides an implementation for ISuggestedAction.IconMoniker but with a return type of "ImageMoniker from EditorFeatures.dll" whereas ISuggestedAction is defined with a return type of "ImageMoniker from Intellisense.dll".  This confuses mono when it's trying to work out the method overrides from SuggestedAction.

----

We have a PR open to improve the assertion message to report more of the details of why loading method overrides failed: https://github.com/mono/mono/pull/6069
Comment 4 Oleg Tkachenko 2017-11-22 00:27:13 UTC
That's very bad news. Aleksey, can you suggest any workaround or guidance here please?
ImageMoniker is pretty ubiquitous in Visual Studio API and it's embedded into many assemblies. Is there any way to still use these assemblies in Mono?
Comment 5 Kirill Osenkov 2017-11-29 22:38:40 UTC
The Visual Studio team has agreed on a workaround for this issue - a new type that is not from an interop assembly.