Installing NHibernate in your application can be challenging. Trying to keep up with new versions and finding information and examples for that particular version is sometimes difficult. Most of the issues I encountered were due to mashing different versions and hoping that all of the parts will work together. While trying to install NHibernate 2.0.1.GA in an Asp.Net MVC 1.0 web application I found the following errors and their fixes.
1) Using the wrong namespace. You might be following an old example from a previous version using:
And maybe getting the following exception:
NHibernate.Cfg.HibernateConfigException was unhandled by user code
Message=”<session-factory xmlns=’urn:nhibernate-configuration-2.2′> element was not found in the configuration file.”
To solve this just replaced your configuration with the new namespace :
2) MappingException :
NHibernate.MappingException was unhandled by user code
Message=”Unknown entity class: MyDomain.EntityClassName”
For me, NHibernate was unable to find the particular hbm.xml files, so after placing the files in a better location I also make sure to explicitly give the location to the config file:
3) Exception: The following types may not be used as proxies: MyDomain.MyClass: method set_MyProperty should be virtual.
Solution: NHibernate requires the properties to be “virtual”.
Message=”The type initializer for ‘NHibernate.Proxy.Poco.Castle.CastleProxyFactory’ threw an exception.”
Solution: Add the “Castle.DynamicProxy2.dll” from the NHibernate installation folder as a reference.