两个不同的程序集版本“定位的程序集的清单定义与程序集引用不匹配”
我正在开发一个项目,需要使用 NHibernate 的 Mysql 连接器 (Mysql.Data.dll)。我还想引用同一项目中的另一个项目(Migrator.NET)。问题是,即使 Migrator.NET 是通过引用特定版本 = false 的 MySql.Data 构建的,它仍然尝试引用构建库时使用的旧版本的 MySql.Data,而不是仅使用现有版本..我得到了标题中列出的异常:
----> System.IO.FileLoadException:无法加载文件或程序集 'MySql.Data,版本=1.0.10.1, 文化=中立, PublicKeyToken=c5687fc88969c44d' 或 它的依赖项之一。位于的 程序集的清单定义确实 与装配参考不匹配。 (HRESULT 异常:0x80131040)
我在主程序集中引用的版本是 6.1.3.0。如何让两个程序集合作?
编辑:
对于那些指定程序集绑定重定向的人,我已经进行了设置:
<?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>
我在另一个项目中引用此主程序集,但仍然遇到相同的错误。如果我的主程序集被复制到本地以便在其他程序集中使用,它是否会使用 app.config 中的设置,或者是否必须在引用我的主程序集的每个应用程序或程序集中包含此信息?
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:
----> 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)
The version I am referencing in the main assembly is 6.1.3.0. How do I get the two assemblies to cooperate?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您正在寻找程序集绑定重定向。
这允许您配置应用程序以查找不同的程序集版本。
You are looking for Assembly Binding Redirection.
This allows you to configure an application to look for a different assembly version.
这是一个非常严重的版本不匹配。当版本差异如此之大时,绑定重定向不会有帮助。顺便说一句,您弄错了,您希望 newVersion 与找到的版本相匹配。但不要去那里。
看着 Migrator.NET 下载,我想我看到了问题所在。 lib 文件夹包含真正旧版本的 MySql.Data.dll,它是在 .NET 1.0 上运行的。首先对其进行修改,然后尝试使用该程序集的版本 6 进行重建。祝你好运,我想你会需要它。
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.
Looking at the Migrator.NET download, I think I see the problem. The lib folder contains a really old 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.
如果您拥有该程序集的两个版本,一种选择是并排使用它们,并简单地将应用程序配置为在正确的位置查找。您可以通过在 app.config 中添加一些行来完成此操作,但对我来说,最可靠的方法始终是注册到 AppDomain.AssemblyResolve 事件并提供所需库的路径。
对于一个简单的示例,您可以查看此处(回答一个不太相关的问题,但使用相同的技术;))
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.AssemblyResolve
event and provide the path for the library that is needed.For a simple example you can have a look here (an answer for a not-very related question, but using the same technique ;))
简单的解决方案是从 Migrator.NET 项目中删除 Mysql.data.dll (对旧 MySql 版本的引用)引用,并添加新的引用 MySql.data.dll (另一个项目使用的相同版本)。再次构建 Migrator.NET,现在一切都应该可以正常工作。我面临着同样的问题,我提到的解决方案对我来说非常有效
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
我也面临同样的问题,并且无法通过上述任何解决方案解决。
所以最后我找到了另一个解决方案......
从解决方案资源管理器中的project=>Properties 中的license.licx 文件中删除所有内容。
当我从该文件中删除所有内容时,它允许我成功构建项目
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.
When I removed everything from this file, its allowing me to build the project successfully