Assembly loading issue with netcore3.1 and Nunit

Viewed 159

I am having an issue (i.e. ReflectionTypeLoadExceptions) with assembly loading in a netcore3.1 application, specifically when using "NUnit.ConsoleRunner.NetCore --version 3.12-beta2" to load unit test assemblies which depend on other assemblies, CopyLocal is set to false for the project-references, although all assemblies are in the same directory.

When CopyLocal is set to false for a particular reference, the .deps.json file will not contain all the entries required for the dependee to be loaded by the AssemblyLoadContext directly, and so the AssemblyLoadContext.Resolving callback/event is fired, but not handled in nunit, or handled incorrectly. The ReflectionTypeLoadException is thrown later, when nunit calls assembly.GetTypes().

A simple demo of the issue can be found here: https://github.com/Ian144/NunitAssemblyLoadIssue.git, that includes a console-app that uses a custom AssemblyLoadContext to demonstrate the issue, or if "NUnit.ConsoleRunner.NetCore --version 3.12-beta2" is installed, just run "nunit AssemblyA.dll" from the output directory. In the demo, AssemblyA contains nunit tests, and has a project reference to AssemblyB with copyLocal set to false.

So, is there an issue with the nunit netcore runner, which should be handling the AssemblyLoadContext.Resolving event? or is there a different way to get assembly loading working under this circumstance?

thanks, Ian

1 Answers

There's some known issues with assembly loading in the beta2 version that were highlighted in the release notes.

The good news is, we've just merged a pull request that we think might fix it. There's a link to the pull request below, which also has details of where to find an updated version, and an appeal for people to try it out. Would appreciate if you could give it a whirl and let us know how it goes!

https://github.com/nunit/nunit-console/pull/942

Related