Could not load file or assembly in NHibernate

These files should be in the same directory as the referenced file, NHibernate.dll:

  • Antlr3.Runtime.dll
  • Iesi.Collections.dll
  • log4net.dll
  • Castle.Core.dll
  • Castle.DynamicProxy2.dll

Also you should add a reference or copy this one too:

  • NHibernate.ByteCode.Castle.dll

I'm assuming you recently upgraded NHibernate to 2.1?

If so, my guess is you have different projects referencing different versions of NHibernate.

This happened to me and is harder to track down than you might think.

These are the steps I took to solve it:

  1. Delete all files in all bin directories in your projects. Usually Clean Solution works well for this, but it doesn't, you may have to do it with a command line call or by hand
  2. Edit all your .csproj files. Edit them either with a text editor or do the Unload Project then edit your .csproj file.
  3. Make sure ALL your HintPath nodes point to the same (new) version of the DLL

That will hopefully clear up this issue for you.


As a future reference: If your're experiencing the same issues Randy Klingelheber pointed out (dependency problems between NHibernate and FluentNHibernate, or any other dependent library), you can specify a redirection for the assemblies that target the old version in app.config. This prevents one from having to recompile the dependent assembly.

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

This code redirects requests for the old version (3.0.0.3001 in my case) to the one actually used (3.0.0.4000). The publicKeyToken is included in the error message.