views:

5474

answers:

4

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?

+1  A: 

You are looking for Assembly Binding Redirection.

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

Oded
I must be doing it wrong because it's not working.
snicker
What's the PublicKeyToken of the newer assembly?
Oded
c5687fc88969c44d
snicker
Have you set the required permissions, as described: http://msdn.microsoft.com/en-us/library/c745b34k.aspx ?
Oded
+1  A: 

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 ;))

Thomas Wanner
+1  A: 

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.

Hans Passant
This was my last resort but half expected that I'd have to build it myself.
snicker
This is what I had to do. Couldn't get assembly binding redirection to work. Crossing my fingers.
snicker
I guess I never followed up.. I did this and it's been working fine.
snicker
A: 

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

Pankaj
Thanks. That is what the accepted answer mentioned to do, and I did that. It did work =]
snicker