Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to diagnose Resharper Unit Test Runner "Unable to load one or more of the requested types" error

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)
like image 583
Jack Ukleja Avatar asked Jun 24 '16 06:06

Jack Ukleja


1 Answers

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();
    }
}
like image 119
Jack Ukleja Avatar answered Oct 08 '22 01:10

Jack Ukleja