NHibernate.MappingException: Unknown entity class

The dreaded “NHibernate.MappingException: Unknown entity class” exception thrown by NHibernate in your .NET web application indicates that the class you are trying to map in your .hbm.xml file cannot be located for some reason.

The first thing to check is to right-click on each of your .hbm.xml files and make sure the Build Action property is set to “Embeded Resource.” This tells .NET to compile the mapping file into the Assembly .dll

If you confirmed that the Build Action is correct then for some reason NHibernate cannot locate your class within the project. Double check that the path to your class is correct. If you’re building a .NET 2.0 website and your model code is inside the App_Code directory, make sure that you have specified the Assembly name of “App_Code”. The .NET framework automatically creates this assembly name for your web project.

65 Responses to “NHibernate.MappingException: Unknown entity class”

  1. Juan P March 17, 2010 at 10:30 am #

    Hi from Mexico!
    Thank you so much!!

  2. peter March 17, 2010 at 3:45 pm #

    in web.config

    did it for me

    thanks for this blog

  3. Dedeco May 12, 2010 at 9:16 pm #

    Thanks a lot!! Works for me “set to “Embeded Resource.””.

  4. Mugabi September 12, 2010 at 9:52 pm #

    Tks GENIO!!!!!

  5. Mohsin October 1, 2010 at 12:30 am #

    Thanks man !!!

  6. vijay chinatal November 25, 2010 at 5:27 am #

    thanks a lot

    • sekhar February 15, 2011 at 5:23 am #

      Thanx man

  7. fararz March 24, 2011 at 2:48 am #

    wah wah .. :D .. thanks alot

  8. Siriquelle March 24, 2011 at 7:52 am #

    Thanks :)

  9. Mahesh October 20, 2011 at 4:51 am #

    Thanks a lot…..

  10. Pava January 2, 2012 at 4:59 am #

    Thanks,Guys I have faced the same problem but my mistake was incorrect file name.
    I have typed user,nbm.xml insterad of user.hbm.xml.

    Cheers..

  11. sam January 27, 2012 at 4:20 am #

    thanks alot

  12. Taha February 29, 2012 at 5:03 am #

    I am getting the error when the iSession.save(“[className]“) method runs
    Please help

  13. Stone March 21, 2012 at 6:13 am #

    And check that your file is correctly named .hbm.xml
    <== YOu saved my life!!! :D

  14. Pradeep April 16, 2012 at 6:05 am #

    superb..nice solution..just we need to add in configuration file…

  15. Ghanshyam May 25, 2012 at 8:06 am #

    Thanks buddy you saved my lot’s of time. I got little bit confident in NHibernet

Leave a Reply

Please leave these two fields as-is: