I just wasted time on something really stupid while i was upgrading to NHibernate 2.0 alpha 1, so i'm posting it here just in case someone else runs into this...
With NHibernate 1.2, i created my SessionFactory like this:
Configuration configuration = new Configuration()
.AddAssembly("MyMappingAssembly");
_sessionFactory = configuration.BuildSessionFactory();
But it didn't work with NHibernate 2.0, i got the following exception:
failed: NHibernate.MappingException : Could not compile the mapping document: Northwind.Domain.Mappings.Region.hbm.xml
----> System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.
TearDown : System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.NullReferenceException : Object reference not set to an instance of an object.
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Cfg\Configuration.cs(262,0): at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Cfg\Configuration.cs(436,0): at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Cfg\Configuration.cs(1557,0): at NHibernate.Cfg.Configuration.ProcessMappingsQueue()
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Cfg\Configuration.cs(1548,0): at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document)
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Cfg\Configuration.cs(1541,0): at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name)
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Cfg\Configuration.cs(506,0): at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Cfg\Configuration.cs(544,0): at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Cfg\Configuration.cs(615,0): at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Cfg\Configuration.cs(601,0): at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
C:\mydocs\src\Northwind\trunk\Northwind\Northwind.Tests\Domain\Mappings\NHibernateTest.cs(27,0): at Northwind.Tests.Domain.Mappings.NHibernateTest.SetUp()
--KeyNotFoundException
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary2.get_Item(TKey key)
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Dialect\Dialect.cs(173,0): at NHibernate.Dialect.Dialect.GetDialect(IDictionary2 props)
c:\DATA\Projects\nhibernate\2.0.x\copy1\nhibernate\src\NHibernate\Cfg\Configuration.cs(428,0): at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
Apparently, it failed when trying to instantiate the Dialect class to use. So i figured something must have changed in the configuration so i checked everything and it looked alright to me. I tried a few things but i just couldn't get it working, so i downloaded the alpha 1 code so i could step through it and see why it wouldn't configure properly... turns out that it just didn't read the configuration settings at all. In NHibernate 1.2, it automatically did this, but now it's a required explicit step. Changing my above code to this worked:
Configuration configuration = new Configuration()
.Configure()
.AddAssembly("MyMappingAssembly");
_sessionFactory = configuration.BuildSessionFactory();