Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 8219 [details]
Sample project reproducing the issue
The attached project reproduces an issue in the following Scenario:
* PCL projet (Profile 47) uses various standard Nuget packages (HttpClient, Async support etc.)
* NUnit test project (.NET 4.5) references and executes PCL, using NitoAsyncEx.AsyncContext (NitoAsyncEx is a PCL itself).
When running the test, I receive the following error:
TypeLoadException: Could not load type 'System.Object' from assembly 'System.Runtime, Version=18.104.22.168, Culture...'
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object,System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object parameters, System.Globalization.CultureInfo culture) [0x00054] in /private/tmp/source-mono-mac-3.10.0-branch/bockbuild-mono-3.10.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.10.0/mcs/class/corlib/System.Reflection/MonoMethod.cs:230
The compiler should under no circumstances emit a reference to System.Object in the System.Runtime assembly anywhere (it's a primitive type after all) and even then we should see it unified to the mscorlib type. So something's seriously wrong here... and I have a feeling that it is related to the PCL build in some way.
I have taken a further look at the NitoAsyncEx assembly and narrowed it down that there is a problem with Mono executing PCL assemblies compiled for Profile 259.
In particular, the NitoAsyncEx.dll referenced from the test project contains this (ildasm output):
.class public auto ansi sealed beforefieldinit Nito.AsyncEx.AsyncContext
So what I assume happens is that the Mono runtime takes this literally and tries to resolve the System.Runtime.dll from the Library.Test/bin/Debug folder, where it actually finds one that is a PCL shim assembly from the Microsoft.Bcl package that was referenced by the Library project. Library.csproj contains
So to summarize: Mono has a problem executing assemblies compiled for Profile 259, when as shim System.Runtime.dll is present.
I can't exactly say whether this is "by design" or a bug in the mono runtime. Will check what the MS CLR does in this case.
PCLs and properly building projects that have them makes my head hurt some times.
Martin, any news on this bug?
Any update? Just hit this issue again today in a different context.
I can confirm this problem still persists in mono --version
Mono JIT compiler version 3.10.0 ((detached/92c4884 Thu Nov 13 23:27:38 EST 2014)
the same problem here, in this case using System.IO.Stream.
I do not include a reproducing project, but situation is as follows
- a PCL library with a base class that uses System.IO.Stream.
- a NUnit test project which derives the base class and also makes use of System.IO.Stream.
In all cases, everything compiles fins, but:
- if the PCL library is set to profile 259, a TypeLoadException is thrown when executing the tests using NUnit, previous to any test execution, stating that the base class (from the PCL library) cannot be loaded (both from within Xamarin Studio and invoking nunit-console).
- if the PCL library is set to profile 78, no exception is thrown and the tests execute.
All this happens with following component versions, under Mac OS:
- Mono JIT compiler version 4.0.1 ((detached/ed1d3ec Tue May 26 17:22:37 EDT 2015)
- NUnit-Console version 22.214.171.12450
This also happens with NUnit 2.4.8 (which is shipped by default with this version of mono).
I'm still having this issue with NitoAsyncEx on Xamarin Studio 6.2 (build 1778) for Mac. Is a fix likely at any point in the future?
This is down to incorrect System.Runtime.dll in bin/Debug folder. I don't know how you got it there but deleting everything and clean build does not copy it there.
We still have an issue as we should not load the assembly but I made a separate ticket for that.