11
votes

I am using the 1.0 RTM of Fluent Nhibernate, with a 3.0 build of NHibernate. In order to do this, I need to add the following to my .config file:

  <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="NHibernate" culture="neutral" publicKeyToken="aa95f207798dfdb4"/>
    <bindingRedirect oldVersion="2.1.0.4000" newVersion="3.0.0.1001"/>
  </dependentAssembly>
</assemblyBinding>

This works great when running integration tests with the TestDriven.net plugin, but fails in the NUnit gui or console runner with the following error:

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

How do I get NUnit to respect my bindingRedirect and run my integration tests successfully?

2

2 Answers

13
votes

I've had similar issues when running nunit on a CI Server (bamboo, to be specific). The way I understand it is that if nunit is running in its own process space (like you're just just running it from command line), then it can correctly read the .dll.config assembly binding redirects. However, if your CI Server is running nunit within the CI Server's process space, then it tries to get the config from the parent process. To ensure that nunit gets run in its own process space, add the command line option /process:multiple. At least, that is what worked for me so that nunit would properly find the redirect bindings.

TL;DR: use the command line option /process:multiple

3
votes

The key is putting it in the correct .config file. See Does redirecting assembly binding work for unit testing with a test runner?.

Another approach would be compiling fluent-nhibernate against NHibernate 3.0. If it has compilation errors, ask the dev team and/or fork the source and make it compile.