我正在尝试在C#Windows窗体应用程序(Visual Studio 2005)中运行一些单元测试,但出现以下错误:

System.IO.FileLoadException:未能加载文件或程序集“Utility,Version=1.2.0.200,Culture=neutral,PublicKeyToken=764d581291d764f7”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(HRESULT的异常:0x80131040)**位于x.Foo.FooGO()位于Foo.cs:line 123中的x.Foo.Foo2(String groupName_)位于FooTests.cs:line 98中的x.Foo.UnitTests.FooTests.TestFoo()**System.IO.FileLoadException:未能加载文件或程序集“Utility,Version=1.2.0.203,Culture=neutral,PublicKeyToken=764d581291d764f7”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(HRESULT的异常:0x80131040)

我查阅了我的参考资料,我只参考了实用程序版本1.2.0.203(另一个是旧版本)。

关于我如何找出试图引用此DLL文件的旧版本的内容,有什么建议吗?

此外,我想我的硬盘上甚至没有这个旧组件。是否有任何工具可以搜索此旧版本的程序集?


当前回答

没有适合我的解决方案。我尝试了清理项目解决方案、删除bin、更新包、降级包等……两个小时后,我用程序集从项目加载了默认App.config,并在那里更改了错误的引用版本:

<dependentAssembly>
    <assemblyIdentity name="Microsoft.IdentityModel.Logging" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
</dependentAssembly>

to:

<dependentAssembly>
    <assemblyIdentity name="Microsoft.IdentityModel.Logging" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.14.0.0" newVersion="5.5.0.0" />
</dependentAssembly>

在这之后,我清理了这个项目,再次构建它,它成功了。没有警告没有问题。

其他回答

我添加了一个NuGet包,结果发现我的应用程序的黑盒部分引用了旧版本的库。

我删除了包并引用了旧版本的静态DLL文件,但web.config文件从未从以下位置更新:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

恢复到卸载包时应该恢复的状态:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.5.0.0" />
</dependentAssembly>

我想补充一下,我正在创建一个基本的ASP.NET MVC 4项目,并通过NuGet添加了DotNetOpenAuth.AspNet。在我引用Microsoft.Web.WebPages.OAuth的不匹配DLL文件后,这导致了相同的错误。

为了修复它,我做了一个更新包,并清理了完整重建的解决方案。

这对我来说很有效,有点懒,但时间就是金钱:-P

就我而言,问题出在椅子和键盘之间:-)

Could not load file or assembly 'DotNetOpenAuth.Core, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)

两个或多个不同的程序集希望使用不同版本的DotNetOpenAuth库,这不是问题。此外,在我的本地计算机上,NuGet自动更新了web.config:

<dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>

然后我意识到我忘记了将新的web.config复制/部署到生产服务器。因此,如果您有手动部署web.config的方法,请检查它是否已更新。如果生产服务器的web.config完全不同,则必须在使用NuGet后同步合并这些dependentAssembly部分。

发生在我身上的System.ValueTuple

意外错误无法加载文件或程序集“System.ValueTuple,版本=4.0.1.0,文化=中性,PublicKeyToken=cc7b13ffcd2ddd51'或它的一个依赖项。系统找不到指定的文件。

通过在发生错误的计算机上安装.NET Framework 4.7.2 Runtime解决了此问题。简单且无需添加bindingRedirect、修改GAC或降级NuGet包等。

https://dotnet.microsoft.com/download/dotnet-framework/net472

只需删除项目的bin文件夹中的内容并重新生成解决方案就解决了我的问题。