There's a bug in
NHibernate.Cfg.Configuration.Mapping.GetPersistentClass(string className) caused by incorrect Dictionary usage. If you have forgot to map a class, you would normally get a MappingException describing which class is unmapped. From this particular class, however, you get a KeyNotFoundException.
The current source code is:
Code:
PersistentClass pc = configuration.classes[className];
if (pc == null)
{
throw new MappingException("persistent class not known: " + className);
}
return pc;
However, a Dictionary will not return null if a key does not exist. You will get a KeyNotFoundException instead. The safe way of using IDictionary is:
Code:
if (!configuration.classes.ContainsKey(className))
{
throw new MappingException("persistent class not known: " + className);
}
return configuration.classes[className];
I've checked out the source code, made this change, and verified that it does in fact throw MappingException instead of the KeyNotFoundException I was getting earlier.
I've also seen that this bug was reported on the forum way back in 2006, but apparently not taken care of. jira.nhibernate.org is unreachable, as always, so I'm unable to search it for relevant issues.
Any opinion on why this hasn't been picked up earlier?