11
votes

When I run or debug my unit tests using Resharper Unit Test Runner, I get a dialog popping up that says "Unit Test Runner failed to run tests - Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information":

enter image description here

Now I have tried rebuilds, cleans, manually deleting folders, visual studio restarts, hardware restarts, looking in output/debug windows, and evening enabling R# "internal" mode so that I can see it's logs (written to %Temp%\JetLogs as I understand), but none of that resolves it or gives any clues at all. I have tried "debugging" R# but again the dialog pops up before the debugger hits any exceptions.

How the hell am I supposed to resolve this? It's extremely annoying!

I'm using:

  • R# 2016.1.2
  • NUnit 3.2.1
  • Visual Studio 2015 Update 2 (14.0.25123)
5
It does seem this error is coming directly from Nunit, but I am surprised that R# does not do anything to help me diagnose this...Jack Ukleja
Resharper doesn't get a chance to, as NUnit catches the exceptions and morphs in a Failed Test Result (without all the details, that is the real problem).Monoman

5 Answers

17
votes

I ended up diagnosing this with a fairly simple method:

I converted my unit test assembly from a class library into a console application and added a Main entry point (shown below). Within there I iterate all of the assemblies types which I hoped would cause all types & dependent assemblies to be loaded, which would reveal any load exceptions. And yes it worked. It quickly threw a System.Reflection.ReflectionTypeLoadException which is the canonical source of the error message "Unable to load one or more...". In the debugger I could examine the LoaderExceptions property which told me what the underlying problem was.

public class Program
{ 
    public static void Main(string[] args)
    {
        var types = Assembly.GetExecutingAssembly().GetTypes();
    }
}
12
votes

Schneider's answer will work just fine but if there are more lazy people out there you can check the LoaderExceptions in PowerShell a bit faster.

[Reflection.Assembly]::LoadFile('<path to your assembly>') | % {$_.GetTypes()}
$Error[0].Exception.InnerException.LoaderExceptions
0
votes

I resolved the same problem in Visual Studio 2017 by closing Visual Studio, deleting the .vs and obj folders of the assembly which wouldn't load, and then reopening Visual Studio and running the tests again.

0
votes

I experienced the same problem with visual studio Express 2017. Tried Schneider's approach but no exception was thrown. Eventually, I created a new project and moved all files of the project that had this problem to the new project and problem solved.

0
votes

I had a similar issue, and finally got it working by installing this nuget package (was unit testing a mvc core project) Microsoft.NET.Test.Sdk