C# 两个不同的程序集版本“定位的程序集的清单定义与程序集引用不匹配”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2284017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:03:37  来源:igfitidea点击:

Two different assembly versions "The located assembly's manifest definition does not match the assembly reference"

c#nhibernateassembliesmigratordotnet

提问by snicker

I have a project that I am working on that requires the use of the Mysql Connector for NHibernate, (Mysql.Data.dll). I also want to reference another project (Migrator.NET) in the same project. The problem is even though Migrator.NET is built with the reference to MySql.Data with specific version = false, it still tries to reference the older version of MySql.Data that the library was built with instead of just using the version that is there.. and I get the exception listed in the title:

我有一个我正在处理的项目,它需要使用用于 NHibernate 的 Mysql 连接器(Mysql.Data.dll)。我还想在同一个项目中引用另一个项目 (Migrator.NET)。问题是,即使 Migrator.NET 是使用特定版本 = false 的 MySql.Data 引用构建的,它仍然会尝试引用构建库的旧版本 MySql.Data,而不是仅使用现有版本.. 我得到了标题中列出的异常:

----> System.IO.FileLoadException : Could not load file or assembly 'MySql.Data, Version=1.0.10.1, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

----> System.IO.FileLoadException : 无法加载文件或程序集“MySql.Data, Version=1.0.10.1, Culture=neutral, PublicKeyToken=c5687fc88969c44d”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)

The version I am referencing in the main assembly is 6.1.3.0. How do I get the two assemblies to cooperate?

我在主程序集中引用的版本是 6.1.3.0。我如何让两个程序集合作?

Edit:

编辑:

For those of you specifying Assembly Binding Redirection, I have set this up:

对于那些指定程序集绑定重定向的人,我已经设置了这个:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-6.1.3.0" newVersion="6.1.3.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

I am referencing this the main assembly in another project and still getting the same errors. If my main assembly is copied local to be used in the other assembly, will it use the settings in app.config or does this information have to be included with every application or assembly that references my main assembly?

我在另一个项目中引用了这个主程序集,但仍然遇到相同的错误。如果我的主程序集被复制到本地以在其他程序集中使用,它是否会使用 app.config 中的设置,或者此信息是否必须包含在引用我的主程序集的每个应用程序或程序集中?

采纳答案by Hans Passant

That's a pretty gross version mismatch. bindingRedirect is not going to help when the versions differ so much. You got it wrong btw, you'd want newVersion to match the one that was found. But don't go there.

这是一个非常严重的版本不匹配。当版本差异如此之大时,bindingRedirect 将无济于事。顺便说一句,您弄错了,您希望 newVersion 与找到的那个相匹配。但不要去那里。

Looking at the Migrator.NET download, I think I see the problem. The lib folder contains a reallyold version of MySql.Data.dll, it was made to run on .NET 1.0. Start by zapping it and try to rebuild with version 6 of that assembly. Good luck, I think you'll need it.

查看 Migrator.NET 下载,我想我看到了问题。lib 文件夹包含一个非常旧的 MySql.Data.dll 版本,它是为了在 .NET 1.0 上运行而设计的。首先将其删除并尝试使用该程序集的版本 6 进行重建。祝你好运,我想你会需要它。

回答by Oded

You are looking for Assembly Binding Redirection.

您正在寻找程序集绑定重定向

This allows you to configure an application to look for a different assembly version.

这允许您配置应用程序以查找不同的程序集版本。

回答by Tomas Vana

In case you have both versions of the assembly one option would be to use them side by side and simply configure the application to look in the right place. You can do this by putting some lines in the app.config, but for me the most reliable way was always to register to the AppDomain.AssemblyResolveevent and provide the path for the library that is needed.

如果您有两个版本的程序集,一种选择是将它们并排使用,然后简单地将应用程序配置为在正确的位置查找。您可以通过在 app.config 中放置一些行来完成此操作,但对我而言,最可靠的方法始终是注册AppDomain.AssemblyResolve事件并提供所需库的路径。

For a simple example you can have a look here(an answer for a not-very related question, but using the same technique ;))

对于一个简单的例子,你可以看看here(一个不太相关的问题的答案,但使用相同的技术;))

回答by Pankaj

The simple solution is remove the Mysql.data.dll (that reference to old MySql version) reference from the Migrator.NET project and add new reference MySql.data.dll (the same version used by another project). Build the Migrator.NET again and now all should work fine. I was facing the same issue and the solution I mentioned worked perfectly for me

简单的解决方案是从 Migrator.NET 项目中删除 Mysql.data.dll(对旧 MySql 版本的引用)引用并添加新引用 MySql.data.dll(另一个项目使用的相同版本)。再次构建 Migrator.NET,现在一切正常。我遇到了同样的问题,我提到的解决方案非常适合我

回答by Vijay Sutaria

I was also facing the same issue, and was not able to solve by any of the above solution. So finally I found one more solution for this... Remove everything from license.licx file in project=>Properties in solution explorer.

我也面临同样的问题,无法通过上述任何解决方案解决。所以最后我找到了另一个解决方案......从解决方案资源管理器中的项目 => 属性中的 license.licx 文件中删除所有内容。

When I removed everything from this file, its allowing me to build the project successfully

当我从这个文件中删除所有内容时,它允许我成功构建项目