我正在尝试在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文件的旧版本的内容,有什么建议吗?

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


当前回答

从文件夹位置手动删除旧程序集,然后将引用添加到新程序集可能会有所帮助。

其他回答

.NET程序集加载器:

找不到1.2.0.203但确实找到了1.2.0.200

此程序集与请求的程序集不匹配,因此会出现此错误。

简单地说,它找不到被引用的程序集。通过将程序集放在GAC或应用程序路径中,确保它可以找到正确的程序集。

运行以下命令将程序集dll文件添加到GAC:

gacutil /i "path/to/my.dll"

另请参见https://learn.microsoft.com/archive/blogs/junfeng/the-located-assemblys-manifest-definition-with-name-xxx-dll-does-not-match-the-assembly-reference.

由于引用了与我正在生成的程序集同名的程序集,我收到了此错误消息。

这已编译,但它用当前项目程序集覆盖引用的程序集,从而导致错误。

为了解决这个问题,我更改了项目的名称,并通过右键单击项目并选择“财产”来更改可用的程序集财产。

我添加了一个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

您可能在assemblyBinding中有错误的掘金版本,请尝试:

删除web.config/app.config中的所有程序集绑定内容:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.3.0" newVersion="3.1.3.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.3.0" newVersion="3.1.3.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
  </dependentAssembly>
</assemblyBinding>

在包管理器控制台中键入:添加BindingRedirect生成所有必要的绑定重定向运行应用程序,看看它是否正常工作。如果没有,请添加包控制台缺少的任何缺少的绑定重定向。