views:

3743

answers:

9

I recently had some problems with the hibernate.cfg.xml as I hadn't had the following line in

<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>

Now that this is fixed I am being shown the following error:

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)

If anyone could guide me on why this error is showing or how I could go about fixing this that would be awsome

Thanks

A: 

It looks like the NHibernate dll isn't being copied to the bin directory of your application. Make sure it's referenced and exists in the bin directory.

lomaxx
The NHibernate.dll is in the bin folder and I have both the following usings in the code "using NHibernate; using NHibernate.Cfg;"
GaryDevenay
A: 

NH has a few other assemblies other than nhibernate.dll. Did you have all of them in (from the same release)?

o.k.w
A: 

You should reference the dependent assemblies (I guess it's "NHibernate.ByteCode.Castle") and set their "copy local" attribute to true.

Meidan Alon
A: 

You probably have code referencing two different versions of the NHibernate DLL. The NHibernate.dll that you download with NHibernate is likely a different version from the one you download with, say, Castle ActiveRecord. Try to stick with just the version of the NHibernate DLL that came with NHibernate.ByteCode.Castle. And make sure you don't have the NHibernate DLL (any version) in your GAC (at least until you get this problem resolved).

Michael Maddox
+5  A: 

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
josemrb
+2  A: 

I recently upgraded our project with the 1.0 RTM version of FluentNHibernate, which required the latest NHibernate bits. This led to the same problem you are having.

Our project's structure was something like this:

Repository root
    Solution
        Web
            References
                DataAccess
        ... other projects/layers ...
        DataAccess
            References
                ..\ReferenceAssemblies\NHibernate.dll
                ..\ReferenceAssemblies\FluentNHibernate.dll
    ReferenceAssemblies

(All external DLL's reside in the ReferenceAssemblies directory.)

My first attempt to solve the problem was by adding a reference to NHibernate.ByteCode.Castle.dll to the DataAccess project. This worked... but only in development...

When I published the web application to our customer acceptance test server (which happens automatically with the help of TeamCity and a script containing a call to aspnet_compiler.exe), the NHibernate.ByteCode.Castle.dll was nowhere to be found.

I am not sure why this is happening, but I suspect that it has something to do with the fact that no code whatsoever in our application actually calls code in that specific dll. Also, there's (correct me if I'm wrong) no hardcoded reference from NHibernate.dll to NHibernate.ByteCode.Castle, so somewhere down the line the (presumably unused) dll is overlooked.

The second (and successful) attempt was to add a reference to the missing dll directly to the web project. Now, I could remove the reference I added in the first attempt without any problems.

(I'm not particularly fond of having such a reference in that particular project, but hey!) :-)

Lette
+1  A: 

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.

CubanX
A: 

In my case, "Clean Solution", followed by "Rebuild Solution" solved the problem.

Tom Bushell
+2  A: 

I had this problem as well.

For me, the issue was that FluentNHibernate expected a different version of NHibernate (2.1.0.4000) than I was including in the project (2.1.2.4000). I stumbled on this by separately downloading the latest releases of each library.

To fix the issue, I changed my NHibernate reference to point to the older version of NHibernate that came with FluenNHibernate 1.0 RTM (2.1.0.4000).

Another solution may be to explicitly set your assembly bindings from the app.config file.

Randy Klingelheber