在使用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);
}此项目具有程序集绑定重定向(但无用):
<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,因此无法找到它。
有人知道它为什么要找这个吗(它是什么?)我该怎么解决这个问题呢?
发布于 2016-06-03 14:49:56
在this博客中尝试该解决方案:
Get-Project -All | Add-BindingRedirect.发布于 2017-03-06 22:23:24
我整个上午都在努力工作,但修复方法是将绑定重定向添加到配置文件中。AutoMoqCustomization似乎依赖于旧版本的Moq,在包依赖项中没有正确引用。通过应用此重定向,您可以绕过需求。
<dependentAssembly>
<assemblyIdentity name=\"Moq\" publicKeyToken=\"69f491c39445e920\" culture=\"neutral\" />
<bindingRedirect oldVersion=\"0.0.0.0-4.2.1510.2205\" newVersion=\"4.2.1510.2205\" />
</dependentAssembly>https://stackoverflow.com/questions/37585696
复制相似问题