I've been using NHibernate for a while. When I configure programmatically, everything's fine. Here's my code:
Code:
cfg.Properties.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
cfg.Properties.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect");
cfg.Properties.Add("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
cfg.Properties.Add("hibernate.connection.connection_string", getConnectionString(key));
cfg.AddAssembly("MyAssembly");
factoryList[key] = cfg.BuildSessionFactory();
Now, I've moved that configuration into a file, as seen below:
Code:
<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
<session-factory>
<property name="hibernate.connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="hibernate.dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="hibernate.connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="hibernate.connection.connection_string">**HA! Like I'm gonna post my connection string to a public forum! :-p**</property>
<mapping assembly="MyAssembly"/>
</session-factory>
</hibernate-configuration>
When I run this, I get a . . . I forget the .NET equivalent of java's NullPointerException. When I take the mapping line out it works fine . . . except, of course, I don't have any mappings loaded. Any ideas, 'cause I'm stumped.
For reference, here's the stack trace I get when I call cfg.Configure(
myXmlTextReader):
Code:
- [System.NullReferenceException] "Object reference not set to an instance of an object."
at NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)
at MyAssembly.Hibernate.HibernateSessionFactory.ConfigureSessionFactory(String key) in C:\\Inetpub\\wwwroot\\personal\\Shared_Libraries\\LIB\\MyAssembly\\HibernateCore.cs:line 267
at MyAssembly.Hibernate.HibernateSessionFactory.PrepareUnitOfWork(HibernateUnitOfWork unit) in C:\\Inetpub\\wwwroot\\personal\\Shared_Libraries\\LIB\\MyAssembly\\HibernateCore.cs:line 189
Thanks in advance