R – Fluent NHibernate: Debugging FluentConfigurationException

exception handlingfluent-nhibernate

I'm enjoying using Fluent NHibernate with AutoMappings but every now and then I get this runtime error when trying to create the fluent configuration: 'An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collections, and InnerException for more detail.'

Now this can mean all sorts of things, but the exception details are not very helpful at all. Sometimes the class that NHibernate fails to process will be listed in the InnerException, other times I get mystic messages like this:

{"(XmlDocument)(3,6): XML validation error: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'property' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in namespace 'urn:nhibernate-mapping-2.2'."}

That doesnt really help me track down the error. Is there any way to get a detailed log of what NHibernate's trying to do (ie, what class/method it's currently auto-mapping) so I can at least identify the part of my code that is causing the problem?

edit:

Known reasons for this error:

  • database connectivity (should be visible in InnerException detail)
  • missing virtual modifier on properties (should indicate type in InnerException detail)
  • missing ID field (gives non specific error as listed above)

Best Answer

Welcome to the wonderful world of NHibernate debugging! I find the the lack of meaningful error messages one of the most annoying aspects of working with NHibernate. Pretty cool when it works, however.

This is a wild guess, but I've seen this message when I've forgotten to add an "Id" property to one of the classes I'm trying to map.

If you read the error message with this in mind, you'll see that this is one of the things that's potentially missing.

Related Topic