I'm having some issues running NHibernate with Microsoft Visual C# 2008 Express Edition. I'm trying a very basic example (User class example, I think from this site). I simply cannot figure out how to configure the enviroment (SQL server, dialect, etc) to NHibernates liking (at least, I think that's the problem).
I'm assuming that the configuration information goes into the App.config file?
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<hibernate-configuration>
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=localhost;Database=NHibernate;Integrated Security=True;</property>
</session-factory>
</hibernate-configuration>
</configuration>
Attempting to run this results in this Exception
Code:
System.TypeInitializationException was unhandled
Message="The type initializer for 'NHibernate.Cfg.Environment' threw an exception."
Source="NHibernate"
TypeName="NHibernate.Cfg.Environment"
StackTrace:
at NHibernate.Cfg.Environment.get_Properties()
at NHibernate.Cfg.Configuration.Reset() in D:\stuff\Visual Studio 2008\Projects\NHibernateTest\NHibernateTest\NHibernate-2.0.0.Beta2-src\src\NHibernate\Cfg\Configuration.cs:line 99
at NHibernate.Cfg.Configuration..ctor(SettingsFactory settingsFactory) in D:\stuff\Visual Studio 2008\Projects\NHibernateTest\NHibernateTest\NHibernate-2.0.0.Beta2-src\src\NHibernate\Cfg\Configuration.cs:line 164
at NHibernate.Cfg.Configuration..ctor() in D:\stuff\Visual Studio 2008\Projects\NHibernateTest\NHibernateTest\NHibernate-2.0.0.Beta2-src\src\NHibernate\Cfg\Configuration.cs:line 180
at NHibernateTest.Program.Main(String[] args) in D:\stuff\Visual Studio 2008\Projects\NHibernateTest\NHibernateTest\Program.cs:line 15
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Configuration.ConfigurationErrorsException
Message="Unrecognized element. (D:\\stuff\\Visual Studio 2008\\Projects\\NHibernateTest\\NHibernateTest\\bin\\Debug\\NHibernateTest.vshost.exe.config line 8)"
Source="System.Configuration"
BareMessage="Unrecognized element."
Filename="D:\\stuff\\Visual Studio 2008\\Projects\\NHibernateTest\\NHibernateTest\\bin\\Debug\\NHibernateTest.vshost.exe.config"
Line=8
StackTrace:
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at NHibernate.Cfg.Environment.LoadGlobalPropertiesFromAppConfig() in D:\stuff\Visual Studio 2008\Projects\NHibernateTest\NHibernateTest\NHibernate-2.0.0.Beta2-src\src\NHibernate\Cfg\Environment.cs:line 189
at NHibernate.Cfg.Environment..cctor() in D:\stuff\Visual Studio 2008\Projects\NHibernateTest\NHibernateTest\NHibernate-2.0.0.Beta2-src\src\NHibernate\Cfg\Environment.cs:line 175
InnerException:
Where "Unrecognized element" and NHibernateTest.vshost.exe.config (exact copy of my in-project App.config) line 8 seems pretty damnening. But that line is the "session-factory", which, afaik, should be correct (reading the Schema seems to confirm this).
I've tried tweaking the App.config a bit (
trying the variation posted in this other thread), but it doesn't seem to matter.
Now, if I either attempt to use the "old" format (like
posted here), OR use a hibernate.cfg.xml external file (I'm not sure where it should go so I copied it around a few places :P) like
suggested here, I seem to get further, but then I die on a different exception, the one about a dialect not being found. Now since dialect only seems to be about which SQL server type you wish to talk to, this makes me think what's happening is that NHibernate is totally bypassing any configuration file, and then dies when it does not know what or where to talk to, SQL wise.
I've tried for the better part of 2 days to get a basic example working, and I'm at a loss. The main documentation describes Java (obviously), so I couldn't find any answers there.
I do use VS 2008 EE and that MSDE for testing at home, which is the setup I've been using so far. At work I'm with a proper full blown SQL 2005 and VS 2005, if that should make any difference.
Browsing the web for any full 2.0 examples hasn't yielded anything. Most of the proper content is about the 1.2 release.
I've tried enabling log4net (basicly including the dll in my project, and using various App.config machinations like there's some examples of in the posts I linked, but I can't get any "log.txt" generated.
Hope there's someone out there who knows whats what :)