【发布时间】:2020-02-14 06:48:46
【问题描述】:
每次我尝试从 Rider IDE 调试单元测试时,测试执行都会失败并出现异常
System.IO.FileLoadException:无法加载文件或程序集 'testhost,文化=中性,PublicKeyToken=null'。找不到或 加载特定文件。 (HRESULT 异常:0x80131621)文件名: 'testhost, Culture=neutral, PublicKeyToken=null'
堆栈跟踪:
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Xunit.Runner.VisualStudio.VsTestRunner.GetAvailableRunnerReporters(IEnumerable`1 sources) in C:\Dev\xunit\xunit\src\xunit.runner.visualstudio\VsTestRunner.cs:line 711
错误只发生在一个复杂的项目中,简单的项目调试器启动并正常工作。
在 Visual Studio 中调试工作正常。 我将不胜感激寻找可能的解决方案的方向。
【问题讨论】:
-
删除调试文件夹并重新编译,应该可以正常工作
-
您的文件是否可能暂时没有准备好?例如 nunit 在设置之前运行测试用例准备。我曾经在测试用例构建中使用一些文件,并且在构建用例之前必须手动复制它。
-
谢谢@Clint,我删除了
obj和bin文件夹,重新编译,运行——同样的错误,抱歉。 -
@LouisGo,我在测试中不使用文件系统,谢谢。
-
@Basin 我的意思是这个测试需要一个程序集,但是有一个
FileLoadException。该组件是否放置在适当的位置?