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 8195 [details]
Project contain code that causes the problem
Attached is a project for a library that contains unit test using the NUnit testing framework that was built and run on a system running Mac OS X 10.9.5. When the unit tests run a System.TypeInitializationException is thrown causing tests to fail. An equivalent project was created in Visual Studio 2013 on Windows 7 x64, using the exact same code, and all the tests were able to run successfully.
The problem was introduce with the static constructor for the InstanceFactory class was added. Removing the constructor allows the tests to succeed, however the constructor is vital to make sure the class operates correctly.
Looks like a problem in the runtime.
I get a ReflectionTyipeLoadException trying to run the test.
The error comes from /Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/AddIns/NUnit/MonoDevelop.NUnit.dll assembly.
But it's hard to tell what fails to load even if the exception hold tons of Could not load file or assembly 'MonoDevelop.Ide, Version=18.104.22.168, Culture=neutral, PublicKeyToken=null' or one of its dependencies. which is suspicious as this assembly should be already loaded
You can try running with MONO_LOG_LEVEL=debug to get more info.
@Zoltan. I'm not sure if your comment was meant for me, Marek, or Mike.
I'm also not sure how someone is supposed to apply the MONO_LOG_LEVEL and set to debug. I went into my General section of the Run options and applied MONO_LOG_LEVEL as an environment variable. I ran the unit test. I didn't see any additional output that looked like it would be useful.
I don't know if the stack trace contained things it would have before using the environment variable. Since I can't copy and paste it anyway it would be difficult for me to include in this bug report.
I looked more into this and this behaviour is by design. Your static constructors loads type from all domain assemblies no matter what they are. In XS case there are assemblies which have not loaded dependencies, specifically MonoDevelop.NUnit.dll which has MonoDevelop.Core dependency.
You cannot simply assume that XS and VS test runners environment will give you same set of loaded assemblies. You need to check only for assemblies relevant to your code and ignore rest.