Das Blog

Debugging one line at a time
$1*/ mo WordPress hosting! Get going with GoDaddy!
Menu
  • Home
  • Coding
    • Entity Framework
    • MVC
    • NHibernate
  • JavaScript
    • TypeScript
  • Hosting
  • SEO
  • Social
  • Database
    • MySql
    • SSIS
  • WP
  • Other
    • CakePHP
    • Error Messages
    • Google Maps
Home
Coding
NHibernate
4 Common errors when setting up NHibernate 2.01
NHibernate

4 Common errors when setting up NHibernate 2.01

Codex Discipulus May 28, 2009

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:

hibernate-configuration xmlns=”urn:nhibernate-mapping-2.2″

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.”

Source=”NHibernate”

StackTrace:

To solve this just replaced your configuration with the new namespace :

<hibernate-configuration xmlns=”urn:nhibernate-configuration-2.2″>

<session-factory>

…

</session-factory>

</hibernate-configuration>

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:

<hibernate-configuration xmlns=”urn:nhibernate-configuration-2.2″>

<session-factory>

<property name=”dialect”>…</property>

<property name=”connection.provider”>…</property>

<property name=”connection.driver_class”>…</property>

<property name=”connection.connection_string”>…</property>

<mapping assembly=”MyDomain.Mvc.Data”/>

</session-factory>

</hibernate-configuration>

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”.

4) Exception:

Message=”The type initializer for ‘NHibernate.Proxy.Poco.Castle.CastleProxyFactory’ threw an exception.”
Source=”NHibernate”
TypeName=”NHibernate.Proxy.Poco.Castle.CastleProxyFactory”

Solution: Add the “Castle.DynamicProxy2.dll” from the NHibernate installation folder as a reference.

Share
Tweet
Google+
Linkedin
Stumble
Email
Next Article

Related Articles

Working, coding and debugging within Visual Studio environment is very …

MVC + Sharp + IIS7 + NHibernate

hibernate_unique_key doesnt exist error
NHibernate error message: "hibernate_unique_key doesn't exist". The error "Table {Project.DbName}.hibernate_unique_key …

NHibernate “hibernate_unique_key doesn’t exist” Error Message

About The Author

Codex Discipulus

Hello, my name is David and I am a disciple of coding, always learning and always ready to help. Welcome to my blog, I hope you find it useful, please send your comments and share an article with your friends.

4 Comments

  1. vijay

    Point (4) is not cleat, can you please elaborate…
    i am getting same error as you have mentioned for point (4).

    December 22, 2010
    • DaCoder

      In #4, the error was caused because my project was missing a reference to “Castle.DynamicProxy2.dll”, which NHibernate needs desperately to be able to build the proxies. In my case, it was an easy fix. In Windows Explorer, I created a \LIB folder in my project, and copy and paste the “Castle.DynamicProxy2.dll” from the NHibernate installation project (the one you download and unzip), and from Visual Studio > View All > Added the \Lib folder and the DLL. Right click the project > Add Reference > Added the DLL from my Lib folder. Additionally, I made sure that the DLL was being COPY during the build process (from the dll’s Properties window in VS). Hope that helps Vijay, and thanks for your comments and views.

      December 23, 2010
  2. vijay

    I have added new hbm and mapping class in different folders.
    before adding above the code was running fine with existing hbm and mapping classes

    December 22, 2010
    • DaCoder

      Why did you add more HDM and mapping classes? New table perhaps?. It just broke recently after that, make sure your mapping is correct. If you are not getting any specific messages as to why is breaking up, try activating NHibernate logging from the config file and hopefully you can get a more deep insight into what is going on. If it was working before, then concentrate only on the code you added. Is a pain to setup sometimes, but once done and is running, NHibernate benefits are huge. Good luck and thanks for posting again Vijay.

      December 23, 2010

Leave a Reply

Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Hosting ASP.Net Core 3.x Worker Service as …
    Using the Worker template now is possible to host an …
  • Calling an HTTPS WCF Service from Net …
    We all know how to call a WCF service from …
  • How to Add a VS Code Project …
    Let’s try to add a Visual Studio Code project to …
  • Step by Step Token based Authentication in …
    Token Authentication is a very popular method to secure a …
  • How to Ignore NuGet Packages in TFS …
    This should be a short post. It is really just …

Categories

  • CakePHP
  • Coding
  • Database
  • Entity Framework
  • Error Messages
  • General
  • Google Maps
  • Hosting
  • JavaScript
  • MVC
  • MySql
  • Net Core
  • NHibernate
  • SEO
  • SSIS
  • TypeScript
  • Wordpress

Tags

ActiveDirectory analytics apps aspnet CakePHP coding database projects design patterns entity framework error messages fatcow first steps ftp github gitlab godaddy google maps api hangfire Hosting iis7 java javascript membership MVC MySql NHibernate nuget nuget packages oracle owin repository SEO sharp ssis t4 tfs thesis token authentication typescript vs2010 vs2015 vs2017 web api Wordpress wp-pagenavi

Das Blog

Debugging one line at a time
Copyright © 2020 Das Blog
ScottsdaleWebStudio.com © All Rights Reserved 2017