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

孤者浪人 提交于 2019-11-30 18:15:15

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();
    }
}

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

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!