Bug 52056 - Type Equivalence and Embedded Interop Types doesn't work on Mono.
Summary: Type Equivalence and Embedded Interop Types doesn't work on Mono.
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Aleksey Kliger
Depends on:
Reported: 2017-01-31 07:46 UTC by Mikhail Filippov
Modified: 2017-11-06 23:02 UTC (History)
5 users (show)

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

Repro project. (73.33 KB, application/zip)
2017-01-31 07:46 UTC, Mikhail Filippov

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:

Description Mikhail Filippov 2017-01-31 07:46:16 UTC
Created attachment 19654 [details]
Repro project.

I made a small sample, it's work on Full NET but doesn't work on Mono.
Comment 1 Ludovic Henry 2017-10-06 23:08:46 UTC
I can reproduce with Mono (2017-10/a3943e28cf8)
Comment 2 Aleksey Kliger 2017-10-09 17:39:44 UTC
Just going to document what I learned so far:

1. The documentation for "Embed Interop Types" is https://docs.microsoft.com/en-us/dotnet/framework/interop/type-equivalence-and-embedded-interop-types?view=netframework-4.7  Basically, two interfaces in two different assemblies can have attributes applied that should convince the runtime to treat them as equivalent.  In a way it doesn't even have anything to do with COM (if you apply the TypeIdentifierAttribute I think it works with purely managed types - I don't think you need to make the type COM visible at all), but the primary usecase is COM.  The user-visible bit that makes it go is the System.Type.IsEquivalentTo method.

The weird part is that the two types being equated could be very different: they might
not be textually the same interface.  The COM usecase is that you embed only the subset of the interface that's actually used in an assembly.

2. Mono's System.Type.IsEquivalentTo (implemented in System.RuntimeTypeHandle.IsEquivalentTo(RuntimeTypeHandle, RuntimeTypeHandle) ) always returns "false".

3. Moreover nothing in native really knows about Embed Interop Types / Type Equivalence.  In particular casting and mono_class_is_assignable_from really makes no provisions for it.   The good news is I think this is an entirely synthetic relation in that you don't have to do anything crazy like share a MonoClass* for the two types that are being identified.  It's just allowing for more types to be considered inter-assignable/castable.  I'm not yet clear on how method lookup will work out.
Comment 3 Rodrigo Kumpera 2017-10-11 00:29:53 UTC
We don't support NoPIA and have no plans to do so.