Friday, 5 June 2009

NHibernate / Castle ByteCode provider – are you running the right number of bits?

Just had one of those head-scratching moments… checked out a known working project including NHibernate and ActiveRecord DLLs, built the whole thing – which built without errors - and then got this lovely message:

Unable to load type 'NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' during configuration of proxy factory class.
Possible causes are:
- The NHibernate.Bytecode provider assembly was not deployed.
- The typeName used to initialize the 'proxyfactory.factory_class' property of the session-factory section is not well formed.

Solution:
Confirm that your deployment folder contains one of the following assemblies:
NHibernate.ByteCode.LinFu.dll
NHibernate.ByteCode.Castle.dll

I’ve seen that message quite a lot recently, but thought we’d well and truly sorted it… well, it turns out there’s another possible cause – you’re building for “Any CPU” on a 64-bit machine and your copy of NHibernate.ByteCode.Castle.dll was built on a colleague’s 32-bit machine. Because this DLL is loaded at runtime there’s no compile-time checking that it’s the right bitness – so it’ll build fine, and then blow up.

Setting VS2008’s platform target to “x86” has solved it in this case – I guess doing a 64-bit build of the relevant DLL would also work.

5 comments:

Darius Damalakas said...

I've got the same issue now.

Built NHibernate from 2.1.x branch, and build Castle from trunk, and now i get this weird message.

the dll file is exactly in the bin directory, so the problem is somwhere else.

I've also forced to load NHibernate.ByteCode.Castle assembly, but it still can not find, even it is already loaded!

It might be the case that i am building against .Net 2.0, but the assemblies where built with nant -t:net-3.5

Darius Damalakas said...

It turned out the problem is that instead of
"NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"

i wrote only
"NHibernate.ByteCode.Castle.ProxyFactoryFactory"
in the config file.

This link helped me find the bug:
http://nhforge.org/blogs/nhibernate/archive/2008/11/09/nh2-1-0-bytecode-providers.aspx

bean said...

I changed the Configuration to x86 and got my problem fixed.

Thanks

Jeff said...

Thank you. I was struggling with this one and got changed it to x86 and it worked fine.

paul.vencill said...

Dylan, you're awesome! I was beating my head against the wall for far too long before incanting just the right words to Google that lead me to your post. Saved my butt!