Upgrading To NHibernate 2.1
Posted by Davy Brion on March 15th, 2009
This is something that a few people (those who don’t read release notes
) are going to run into, so i figured i’d post the solution here.
If your application uses NHibernate 2.0, and you want to upgrade to NHibernate 2.1 you need to add something to your NHibernate configuration. If you just replace NHibernate.dll with the newer version and start your application, you will get an exception with the following message:
The ProxyFactoryFactory was not configured.
Initialize ‘proxyfactory.factory_class’ property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
Example:
<property name=’proxyfactory.factory_class’>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
Example:
<property name=’proxyfactory.factory_class’>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
Pretty helpful message, no? (if only everyone would actually read the content of exception messages)
NHibernate used to default to use Castle’s DynamicProxy to generate runtime proxies, but you now have to explicitly state which proxy factory should be used.
For instance, if you want to use Castle’s DynamixProxy, add a reference to NHibernate.ByteCode.Castle.dll to your project and add the following line to your hibernate.cfg.xml file:
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
If you want to use another proxy factory, add a reference to the correct one (for instance, NHibernate.ByteCode.LinFu.dll) and modify the property in the config file. A proxy factory which uses Spring will also be included soon.
March 15th, 2009 at 4:19 pm
You didn’t see the binaries
The Bytecode for Sping is there.
March 15th, 2009 at 4:24 pm
ah, i thought it was still left out of the build
March 15th, 2009 at 6:21 pm
We hit this exact issue last week – but we’re using ASP.NET MVC and the MvcContrib library in conjunction with Castle ActiveRecord, and immediately following the upgrade, the only error message we got was:
According to MSDN, “execution engine errors are fatal errors that should never occur” – and for some reason, the actual NHibernate config exception wasn’t showing up in the debugger or error messages anywhere – so it took a while to root out the source of the problem. We ended up compiling the entire project from source, including NHibernate and Castle, and this led us the proxy configuration errors described above; hopefully this comment will help anyone else having the same MvcContrib / ExecutionEngineException problems.
March 16th, 2009 at 9:16 am
[...] Upgrading To NHibernate 2.1 – Davy Brion looks at the the additional configuration requirement of NHibernate 2.1 over version 2.0, the ability (and requirement) for you to specify which proxy implementation you want, allowing you to choose what library to take dependency on. [...]
March 24th, 2009 at 1:31 pm
Hi,
Am new to NHibernate development.
Can u sepecify how we can use NHibernate in our app and what configuarion are requred for NHibernate 2.1 Alpha. Am getting the error mentioned above and i dont know where to configure the property.
Thanks in advance
March 24th, 2009 at 1:35 pm
that property needs to be added to the hibernate.cfg.xml file, like it says in the post…
April 3rd, 2009 at 7:11 pm
@Davy
I’m new to NHibernate as well, and have my config stuff in web.config. I do not have a hibernate.cfg.xml file, other settings seem to get loaded from web.config, but this does not.
April 3rd, 2009 at 10:28 pm
@Aaron
you can use the web.config to store nhibernate configuration settings but the format is slightly different. Using the hibernate.cfg.xml config file is typically the easiest solution, just make sure it’s marked as content and is copied to the build output.
June 25th, 2009 at 9:49 am
Hmm, I’m trying to migrate my application to NH2.1 beta, and the first error that comes accross is that the type initializer has thrown an exception while creating the configuration-section handler for hibernate-configuration.
It cannot load the NHibernate assembly, or one of its dependencies … Strange, it seems that this is an error I have that is not related with the proxy-factory issue, since I’ve added this additional property to my Cfg file (and I’ve added a reference to the desired file as well … )
(I’ve never received the exception that you’ve mentionned, the first exception that I’ve been given, is the ‘FileNotFoundException’).
June 25th, 2009 at 9:51 am
http://code.google.com/p/sharp-architecture/issues/detail?id=111#c0
is that what you’re getting?
June 25th, 2009 at 10:11 am
Stupid me has solved the problem 8)7
(No, the problem was not related to Antlr3; the exception really said that NHibernate or one of its assemblies could not be loaded).
In my configSection, I did not specify an exact version. I have referenced the NHibernate assembly from the GAC. Copy local has been set to false on my reference; apparently, the CLR was not able to exactly determine which NHibernate assembly should be loaded. So, I’ve solved it by setting ‘Copy Local’ to true on my NHibernate reference).
Anyway, interesting blog.
August 20th, 2009 at 5:36 am
There are many dependency, and we do have 2 choice:
1. NHibernate.ByteCode.LinFu.ProxyFactoryFactory
2. NHibernate.ByteCode.Castle.ProxyFactoryFactory
August 26th, 2009 at 11:34 am
Thx, man. Your article solve my problem )
September 2nd, 2009 at 8:27 am
Thanks, exactly what I needed!
November 9th, 2009 at 4:00 pm
Hi,
I’m using Fluent NHibernate. Where i should add the line ?
November 9th, 2009 at 4:20 pm
I found the solution:
MsSqlConfiguration.MsSql2005.ConnectionString(c => c.Is(connectionstring)).ProxyFactoryFactory(“NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle”);
February 10th, 2010 at 9:27 pm
I couldn’t find the hibernate.cfg.xml file in my machine. Where is it located?
Thanks!
March 14th, 2010 at 2:11 pm
Hi,
I put the NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle in hibernate.cfg.xml file, and the reference NHibernate.ByteCode.Castle.dll, but shows this error yet:
The ProxyFactoryFactory was not configured.
Initialize ‘proxyfactory.factory_class’ property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
Example:
NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
Example:
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
Is the same error of your post. What do you think that is happenning?