System.IO.FileLoadException: 调试测试时无法加载文件或程序集“testhost”

System.IO.FileLoadException: Could not load file or assembly 'testhost, when debugging tests

每次我尝试从 Rider 调试单元测试时 IDE,测试执行失败并出现异常

System.IO.FileLoadException: Could not load file or assembly 'testhost, Culture=neutral, PublicKeyToken=null'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621) File name: '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 中调试工作正常。 如果能提示寻找可能解决方案的方向,我将不胜感激。

我通过 "nuking" 整个项目解决了这个问题 :)

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

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