NOT处于调试模式时,单元测试无法运行

时间:2022-10-06 20:15:58

I have just branched our Common Business Layer projects from the main to a new branch, and included them in a new solution. Everything compiles but when I run the unit tests I get the following error for every single test...

我刚刚将公共业务层项目从主分支分支到新分支,并将它们包含在新的解决方案中。一切都编译但是当我运行单元测试时,每次测试都会出现以下错误...

Unit Test Adapter threw exception: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

单元测试适配器引发异常:无法加载一个或多个请求的类型。检索LoaderExceptions属性以获取更多信息。

The strange thing is they run fine when I debug them. The error only happens when I run them without the debugger attached.

奇怪的是,当我调试它们时它们运行正常。只有在没有附加调试器的情况下运行它们时才会发生错误。

Failing an outright fix, can anyone tell me how to "Retrieve the LoaderExceptions property"?

如果没有完全修复,有人能告诉我如何“检索LoaderExceptions属性”吗?

5 个解决方案

#1


3  

Try cleaning the solution and trying again.

尝试清洁解决方案并再次尝试。

Also try clicking on the link that appears in yellow bar of the Test Results window, this sometimes gives more information about why tests cannot be run.

还可以尝试单击“测试结果”窗口中黄色栏中显示的链接,这有时会提供有关无法运行测试的原因的详细信息。

#2


5  

I've also seen this, sometimes when the simple cleanup doesn't help, I switch the configuration to Release, clean it up, then back to Debug, clean it up and rebuild (

我也看过这个,有时当简单清理没有帮助时,我将配置切换到Release,清理它,然后返回Debug,清理它并重建(

#3


3  

My psychic debugger says that you're using 64-bit, and your test adapter is set to use 64-bit .NET framework, and devenv is set to 32-bit. Use corflags to force your test adaptor to run using the 32-bit CLR.

我的通灵调试器说您正在使用64位,并且您的测试适配器设置为使用64位.NET框架,devenv设置为32位。使用corflags强制您的测试适配器使用32位CLR运行。

NOTE: Psychic debugger is not always 100% accurate, due to its use of psychic powers :)

注意:心灵调试器并不总是100%准确,因为它使用了通灵力量:)

#4


1  

I did run into the same errors and the cleaning did not do the job.

我确实遇到了同样的错误,清洁工作没有完成。

I resolved this one by going into the TestRunConfig file, Code Coverage Menu, and putting the right SNK file in the "Re-signing Key File" text box.

我通过进入TestRunConfig文件,代码覆盖率菜单,并将正确的SNK文件放入“重新签名密钥文件”文本框中解决了这个问题。

Hope this help.

希望这有帮助。

#5


1  

I ran into the same problems without knowingly having changed anything, so what helped for me was to open the Configuration Manager (Build => Configuration Manager) and make sure that the solution and all its projects are set to "Any CPU". Somehow some of them were set to "x86", after changing this back to "Any CPU" all tests run fine again in Debug and Release mode.

我没有故意改变任何东西遇到了同样的问题,所以对我有帮助的是打开Configuration Manager(Build => Configuration Manager)并确保解决方案及其所有项目都设置为“Any CPU”。不知何故,其中一些被设置为“x86”,在将其更改回“Any CPU”后,所有测试在Debug和Release模式下再次运行正常。

HTH

G.

#1


3  

Try cleaning the solution and trying again.

尝试清洁解决方案并再次尝试。

Also try clicking on the link that appears in yellow bar of the Test Results window, this sometimes gives more information about why tests cannot be run.

还可以尝试单击“测试结果”窗口中黄色栏中显示的链接,这有时会提供有关无法运行测试的原因的详细信息。

#2


5  

I've also seen this, sometimes when the simple cleanup doesn't help, I switch the configuration to Release, clean it up, then back to Debug, clean it up and rebuild (

我也看过这个,有时当简单清理没有帮助时,我将配置切换到Release,清理它,然后返回Debug,清理它并重建(

#3


3  

My psychic debugger says that you're using 64-bit, and your test adapter is set to use 64-bit .NET framework, and devenv is set to 32-bit. Use corflags to force your test adaptor to run using the 32-bit CLR.

我的通灵调试器说您正在使用64位,并且您的测试适配器设置为使用64位.NET框架,devenv设置为32位。使用corflags强制您的测试适配器使用32位CLR运行。

NOTE: Psychic debugger is not always 100% accurate, due to its use of psychic powers :)

注意:心灵调试器并不总是100%准确,因为它使用了通灵力量:)

#4


1  

I did run into the same errors and the cleaning did not do the job.

我确实遇到了同样的错误,清洁工作没有完成。

I resolved this one by going into the TestRunConfig file, Code Coverage Menu, and putting the right SNK file in the "Re-signing Key File" text box.

我通过进入TestRunConfig文件,代码覆盖率菜单,并将正确的SNK文件放入“重新签名密钥文件”文本框中解决了这个问题。

Hope this help.

希望这有帮助。

#5


1  

I ran into the same problems without knowingly having changed anything, so what helped for me was to open the Configuration Manager (Build => Configuration Manager) and make sure that the solution and all its projects are set to "Any CPU". Somehow some of them were set to "x86", after changing this back to "Any CPU" all tests run fine again in Debug and Release mode.

我没有故意改变任何东西遇到了同样的问题,所以对我有帮助的是打开Configuration Manager(Build => Configuration Manager)并确保解决方案及其所有项目都设置为“Any CPU”。不知何故,其中一些被设置为“x86”,在将其更改回“Any CPU”后,所有测试在Debug和Release模式下再次运行正常。

HTH

G.