Monday, December 5, 2011

NullReferenceException on CompileMappingForAllExplicitlyAddedEntities ModelMapper for NHibernate 3.2

If you're using NHibernate 3.2, and when call the CompileMappingForAllExplicitlyAddedEntities() method of your ModelMapper object, you have to check none of your added classes are defined without a namespace.
This could happen if you are added all types defined in your assemblies (calling for example mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes() ), and at least one of your classes is compiled in the empty namespace ...
To solve this error, you have to define these classes in a namespace (it is always a good practice).

The error is caused by the NHibernate source code, because doesn't take care about empty namespaces.

The thread about that problem on nhuser google group.

Happy debugging ^^