views:

104

answers:

2

I am trying to use NHiberanate with NDbUnit but I cannot as NDbUnit tried to load MySql.Data version 1.0.10.1 and NHibernate tries to load version 6.2.2.0 and I can only reference one of them.

Here is the error I get when i try to run NDbUnit

Set Up
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)
   at NDbUnit.Core.MySqlClient.MySqlDbCommandBuilder.GetConnection(String connectionString)
   at NDbUnit.Core.DbCommandBuilder..ctor(String connectionString)
   at NDbUnit.Core.MySqlClient.MySqlDbCommandBuilder..ctor(String connectionString)
   at NDbUnit.Core.MySqlClient.MySqlDbUnitTest.CreateDbCommandBuilder(String connectionString)
   at NDbUnit.Core.NDbUnitTest.GetDbCommandBuilder()
   at NDbUnit.Core.NDbUnitTest.ReadXmlSchema(Stream xmlSchema)
   at NDbUnit.Core.NDbUnitTest.ReadXmlSchema(String xmlSchemaFile)
   at Proteus.Utility.UnitTest.DatabaseUnitTestBase.SaveDatabase(String connectionString, String schemaFilePathName, String datasetFilePathName, DatabaseClientType clientType)
   at TGS.UserAccountControlTest.UserAccountManagerTest._TestFixtureSetup() in C:\Documents and Settings\Michal\My Documents\Visual Studio 2008\Projects\TGS\TGS.UserAccountControlTest\UserAccountManagerTest.cs:line 69

Does anyone have any ideas?

+2  A: 

You could try a binding redirect in the config file:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data"
                          publicKeyToken="c5687fc88969c44d"
                          culture="neutral" />
        <bindingRedirect oldVersion="1.0.10.1"
                         newVersion="6.2.2.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

This might not work if the two assemblies are signed with a different key. Also the gap between V1 and V6 seems pretty big, the methods you rely upon should not have changed between those versions.

Actually in your case it probably should be:

oldVersion="6.2.2.0"
newVersion="1.0.10.1"
Darin Dimitrov
+1  A: 

If the assembly binding redirect feels either 'hacky' (its not at all) or 'inconveniently brittle' (it often is), you can also simply recompile NDbUnit against your 'desired' MySql.Data assembly (since NDbUnit is open source) by getting the source from http://ndbunit.googlecode.com

To my knowledge (as the primary committer for the NDbUnit project) there are NO breaking changes in the MySql.Data betw. v1x and v6x. The intent of the MySql.Data assembly is merely to provide MySql-specific implementations of the interface 'family' that makes up the ADO.NET stack (IDbConnection, IDBCommand, etc.) and so BY DEFINITION there cannot be breaking changes in the MySql.Data assembly from v1 to v6 (since MS hasn't really TOUCHED these interfaces since .NET 2.0 was released).

The ONLY difference between earlier MySql.Data and later MySql.Data implementations of these interfaces is the verison of MySql that they are intended to support so while the 'database-facing' side of this assembly changes over time, the 'code-facing' side of the classes contained in this assembly sort of BY DEFINITION cannot have changed from one ver to the next.

Best of luck~!

sbohlen
Thanks I will be giving this a go next week :D
LnDCobra