简体   繁体   English

如何诊断Resharper Unit Test Runner“无法加载一个或多个请求的类型”错误

[英]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": 当我使用Resharper Unit Test Runner运行或调试我的单元测试时,我弹出一个对话框,说“单元测试运行器无法运行测试 - 无法加载一个或多个请求的类型。检索LoaderExceptions属性以获取更多信息” :

在此输入图像描述

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. 现在我尝试了重建,清理,手动删除文件夹,可视工作室重启,硬件重启,查看输出/调试窗口,以及晚上启用R#“内部”模式,以便我可以看到它的日志(写入%Temp%\\ JetLogs据我了解),但没有一个解决它或提供任何线索。 I have tried "debugging" R# but again the dialog pops up before the debugger hits any exceptions. 我试过“调试”R#但是在调试器遇到任何异常之前,对话框再次弹出。

How the hell am I supposed to resolve this? 我该怎么解决这个问题呢? It's extremely annoying! 这非常烦人!

I'm using: 我正在使用:

  • R# 2016.1.2 R#2016.1.2
  • NUnit 3.2.1 NUnit 3.2.1
  • Visual Studio 2015 Update 2 (14.0.25123) Visual Studio 2015 Update 2(14.0.25123)

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). 我将单元测试程序集从类库转换为控制台应用程序,并添加了一个Main入口点(如下所示)。 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...". 它迅速抛出了System.Reflection.ReflectionTypeLoadException ,它是错误消息“无法加载一个或多个......”的规范来源。 In the debugger I could examine the LoaderExceptions property which told me what the underlying problem was. 在调试器中,我可以检查LoaderExceptions属性,它告诉我底层问题是什么。

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. Schneider的答案会很好用,但如果有更多懒人,你可以更快地检查PowerShell中的LoaderExceptions

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

我通过关闭Visual Studio,删除了无法加载的程序集的.vsobj文件夹,然后重新打开Visual Studio并再次运行测试,在Visual Studio 2017中解决了同样的问题。

I experienced the same problem with visual studio Express 2017. Tried Schneider's approach but no exception was thrown. 我在visual studio Express 2017上遇到了同样的问题。试过Schneider的方法,但没有例外。 Eventually, I created a new project and moved all files of the project that had this problem to the new project and problem solved. 最后,我创建了一个新项目,并将具有此问题的项目的所有文件移动到新项目并解决了问题。

我有一个类似的问题,最后通过安装这个nuget包(单元测试mvc核心项目)得到它的工作Microsoft.NET.Test.Sdk

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EF4无法在测试服务器上加载一种或多种请求的类型 - EF4 Unable to load one or more of the requested types on test server 移动项目后无法加载一种或多种请求的类型 - Gets Unable to load one or more of the requested types after moving the project 无法加载一个或多个请求的类型。 检索loaderexceptions - Unable to load one or more of the requested types. retrieve the loaderexceptions EPiServer:DLL故障-无法加载一种或多种请求的类型 - EPiServer: DLL trouble - Unable to load one or more of the requested types API 错误 - 无法从程序集 JsonApiDotNetCore 加载一种或多种请求的类型方法 CommitAsync - API error - Unable to load one or more of the requested types Method CommitAsync from assembly JsonApiDotNetCore sgen.exe生成错误“无法加载一个或多个请求的类型” - sgen.exe build error “Unable to load one or more of the requested types” 无法加载一个或多个请求的类型。 检索LoaderExceptions属性以获取更多信息。 使用EntityDataSource - Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. with EntityDataSource System.ServiceModel.DomainServices.Hosting:无法加载一种或多种请求的类型 - System.ServiceModel.DomainServices.Hosting : Unable to load one or more of the requested types Resharper单元测试运行器无法查找内容文件 - Resharper Unit Test Runner Can't Find Content Files ReSharper单元测试运行器是否按顺序或与MbUnit并行运行测试? - Does the ReSharper unit test runner run tests sequentially or in parallel with MbUnit?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM