Tuesday, 8 July 2008

Mapping errors with nHibernate in Visual Studio

I've started to get into nHibernate recently and while it's pretty cool to use I'm shocked at the lack of info if you get into problems.

A good example - I was working on a project that already had nHibernate setup and running with exisiting integration tests. I added a new object to the domain, created a new mapping file, project built, all good but when I ran my new integration test I kept getting this error:

Class type <YOURNAMESPACE.YOURCLASS> is not defined within your current mapping files

Finally got fed up searching through Google and asked a collegue who pointed out the reason why.
The error generally means the mapping file isn't being found by nHibernate.

Essentially I was being a bit thick and had named the mapping file newclass.xml instead of newclass.hbm.xml ok ok my bads on that one BUT he also told me the xml file needed to be setup as an embedded resource in Visual Studio (Right click the file - properties and set 'Build Action' to 'Embedded Resource').

Lesson learned and just in case anyone else is stumped out there;
check you have named the mapping file correctly (it should be named the same as the domain object), with the right extension (hbm.xml) and you have specified the file is an embedded resource!!!


Post a Comment

Subscribe to Post Comments [Atom]

<< Home