Bug 26833 - Mono attempts to load concrete class when receiving an interface from an AppDomain
Summary: Mono attempts to load concrete class when receiving an interface from an AppD...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Remoting ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Alexander Kyte
URL:
Depends on:
Blocks:
 
Reported: 2015-02-07 19:43 UTC by June Rhodes
Modified: 2015-03-24 10:52 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 FIXED

Description June Rhodes 2015-02-07 19:43:53 UTC
This occurs on this version of Mono:

Mono JIT compiler version 3.12.0 (tarball Mon Jan 19 15:51:05 GMT 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        LLVM:          supported, not enabled.
        GC:            sgen

As reported here: https://github.com/xunit/xunit/issues/158

The issue is that Mono throws a TypeLoadException on this line of code: https://github.com/xunit/xunit/blob/a76be923dc3761ff6ae15445f7db358e6a2ae595/src/xunit.runner.utility/Frameworks/v2/Xunit2Discoverer.cs#L55

In this case, "Framework.GetDiscoverer" has a return signature of ITestFrameworkDiscoverer, and assigns to a field of type ITestFrameworkDiscoverer.  The framework object is a MarshalByRefObject that points to an object in a different AppDomain.  The assembly that defines ITestFrameworkDiscoverer is loaded in the current AppDomain, but the concrete class is in a different assembly that is not loaded (and is not on a path that will cause it to automatically load).

Under .NET this works fine, and the CLR only needs to know the interface (because the concrete class is never accessed by any mechanism other than the interface's methods, and is never cast).

Under Mono however, it attempts to load the concrete class as it's returned from the AppDomain, thus causing a TypeLoadException when the assembly that contains it is not available (intentionally as the desire is to only communicate by agreed interfaces).
Comment 1 Alexander Kyte 2015-03-24 10:52:44 UTC
After applying the commits in 

https://github.com/mono/mono/pull/1654

the assert unit tests run correctly.