无法加载文件或程序集'Moq,4.2.1502.911'或其依赖项。

15

我在项目中通过管理Nuget包安装了Moq nuget包。项目可以成功构建,但是当我运行测试用例时,它会抛出以下错误。

System.IO.FileLoadException: Could not load file or assembly 'Moq, Version=4.2.1502.911, Culture=neutral, PublicKeyToken=69f491c39445e920' or one of its dependencies

我检查了项目引用,Moq.dll在那里。

同时在测试运行的输出窗口中,我注意到了这个信息。

------ Discover test started ------
Unable to load the test container 'C:\dev\tfs\Main\GUI\Gui.Client\Bin\Debug\Gui.Client.dll' or one of its dependencies. Error details: System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Practices.Prism, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.

========== Discover test finished: 20 found (0:00:03.4941998) ==========
------ Run test started ------
Warning: conflict during test run deployment: deployment item 'c:\dev\tfs\main\gui\test\gui.client.state.tests\bin\debug\Moq.dll' directly or indirectly referenced by the test container 'c:\dev\tfs\main\gui\test\gui.client.state.tests\bin\debug\gui.client.state.tests.dll' cannot be deployed to 'Moq.dll' because otherwise the file 'c:\dev\tfs\main\gui\test\gui.client.state.tests\bin\debug\Moq.dll' would overwrite deployment item '..\ThirdPartyLibraries\NuGetPackages\Moq.4.2.1402.2112\lib\net40\Moq.dll' specified by the test settings.
Warning: Test Run deployment issue: The assembly or module 'NMath' directly or indirectly referenced by the test container 'c:\dev\tfs\main\gui\test\gui.client.state.tests\bin\debug\gui.client.state.tests.dll' was not found.
========== Run test finished: 1 run (0:00:23.2373118) ==========

2
你找到解决这个问题的办法了吗?我遇到了相同错误的类似问题。我有一些 NuGet 包用于测试(我怀疑 Ninject.MockingKernel 是导致这种行为的触发器),在 VS 测试运行 Nunit 插件中它们可以正常工作(测试被执行并且正常工作),但在 nunit gui 中我会遇到此错误,花了一些时间也无法找到问题所在。 - Sergey Novikov
确保运行VS的用户具有dll文件夹的读取权限。您还可以尝试重新安装Nuget包。 - Amir Katz
2个回答

11

遇到了相同的问题。 将所有项目的Moq nuget更新为使用相同的Moq库,对我来说运行正常。

右键单击Moq引用,确保在所有地方使用相同的版本。如果没有,请使用nuget包管理器进行更新。


这对我不起作用 - 使用TFS 15作为构建服务器。 - ryanwebjackson

0
对我来说,问题出在我选择了“启用本机代码调试”以及“抑制JIT编译”。取消选择这些选项,清理并重新构建,问题就不再存在了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接