Two different assembly versions "The located assembly's manifest definition does not match the assembly reference"
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 b开发者_开发问答e 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?
You are looking for Assembly Binding Redirection.
This allows you to configure an application to look for a different assembly version.
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.
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 ;))
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
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
精彩评论