【问题标题】:System.IO.FileLoadException: Could not load file or assembly 'testhost, when debugging testsSystem.IO.FileLoadException:调试测试时无法加载文件或程序集“testhost”
【发布时间】: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,我删除了objbin 文件夹,重新编译,运行——同样的错误,抱歉。
  • @LouisGo,我在测试中不使用文件系统,谢谢。
  • @Basin 我的意思是这个测试需要一个程序集,但是有一个FileLoadException。该组件是否放置在适当的位置?

标签: c# .net-core xunit rider


【解决方案1】:

我通过“核”整个项目解决了这个问题:)

从磁盘中删除整个存储库后
- 克隆存储库返回
- 再次生成 Visual Studio 解决方案文件(我们不会将它们保存在存储库中)
- 构建解决方案
- 运行测试
- 调试其中一项测试 - 调试器正常工作

我从一些 JetBrains 论坛中发现了从 dotnet 位置删除 Micrososft.AspNet.Core 文件夹的建议,虽然建议的方法不起作用,但它让我知道问题可能出在这个特定的解决方案依赖项上。

【讨论】:

猜你喜欢
  • 2022-11-23
  • 2013-08-13
  • 1970-01-01
  • 2014-05-19
  • 2020-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多