gpt4 book ai didi

c# - FileLoadException : Moq and Moq. 资源

转载 作者:太空宇宙 更新时间:2023-11-03 12:45:08 27 4
gpt4 key购买 nike

我在一个使用 Moq 和 AutoFixture.AutoMoq 的特定项目的构建服务器上运行单元测试时遇到问题。这是错误:

System.IO.FileLoadException : Could not load file or assembly 'Moq, Version=4.1.1308.2120, 
Culture=neutral, PublicKeyToken=69f491c39445e920' or one of its dependencies. The located
assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040) at Ploeh.AutoFixture.AutoMoq.MockPostprocessor.Create(Object
request, ISpecimenContext context)

该项目基于 .NET 4.5.1 构建并使用以下 nuget 包(这些版本也用于整个解决方案):

<package id="AutoFixture" version="3.40.1" targetFramework="net451" />
<package id="AutoFixture.AutoMoq" version="3.40.1" targetFramework="net451" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net451" />

这是失败的测试之一(使用 xunit 2.0):

[Fact]
public void SutIsIMessageConverterService()
{
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var sut = fixture.Create<XmlValidationConverterService>();
Assert.IsAssignableFrom<IMessageConverterService>(sut);
}

这个项目有一个程序集绑定(bind)重定向(但没有用):

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1510.2205" newVersion="4.2.1510.2205" />
</dependentAssembly>
</assemblyBinding>

在构建服务器上使用 FUSLOGVW.exe 我找到了更多信息(起初我假设 Moq 没有任何依赖项):

LOG: DisplayName = Moq.resources, Version=4.2.1510.2205, Culture=en-US, PublicKeyToken=69f491c39445e920 (Fully-specified)
LOG: Appbase = file:///D:/ProjectName.Tests
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Users\BuildServerUserName\AppData\Local\Temp\ddf02945-045c-408c-a648-ec5325032f0a
LOG: AppName = ddf02945-045c-408c-a648-ec5325032f0a
Calling assembly : Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920.
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\ProjectName.Tests.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Moq.resources, Version=4.2.1510.2205, Culture=en-US, PublicKeyToken=69f491c39445e920
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///D:/ProjectName.Tests/en-US/Moq.resources.DLL.
LOG: Attempting download of new URL file:///D:/ProjectName.Tests/en-US/Moq.resources/Moq.resources.DLL.
LOG: Attempting download of new URL file:///D:/ProjectName.Tests/en-US/Moq.resources.EXE.
LOG: Attempting download of new URL file:///D:/ProjectName.Tests/en-US/Moq.resources/Moq.resources.EXE.
LOG: All probing URLs attempted and failed.

所以Moq依赖于Moq.resources,找不到。

有谁知道它为什么要寻找这个(它是什么?)以及我该如何解决这个问题?

最佳答案

尝试 this 中的解决方案博客:

  • 从任何 .config 文件中删除该元素及其子元素。
  • 在 Visual Studio 中打开程序包管理器控制台。这可以从 View |其他窗口 |包管理器控制台菜单。
  • 输入这个解决所有问题的神奇命令:Get-Project -All |添加绑定(bind)重定向

关于c# - FileLoadException : Moq and Moq. 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37585696/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com