The type initializer for ‘NHibernate.Cfg.Configuration’ threw an exception

fluent-nhibernate

I am using FluentNHibernate and during the configuration phase I am getting the following error:

Here is the configuration:

public static ISessionFactory CreateSessionFactory()
{
return
Fluently.Configure().Database(
MsSqlConfiguration.MsSql2000.ConnectionString(
c => c.FromConnectionStringWithKey("HighOnCodingConnectionString")))
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf())
.BuildSessionFactory();
}

And here is the error:

[failure] when_instantiating_a_session_factory.should_be_able_to_create_a_session_factory
TestCase 'when_instantiating_a_session_factory.should_be_able_to_create_a_session_factory'
failed: The type initializer for 'NHibernate.Cfg.Configuration' threw an exception.
System.TypeInitializationException
Message: The type initializer for 'NHibernate.Cfg.Configuration' threw an exception.
Source: NHibernate
StackTrace:
at NHibernate.Cfg.Configuration..ctor()
c:\FluentNHibernate\src\FluentNHibernate\Cfg\FluentConfiguration.cs(25,0): at FluentNHibernate.Cfg.FluentConfiguration..ctor()
c:\FluentNHibernate\src\FluentNHibernate\Cfg\Fluently.cs(16,0): at FluentNHibernate.Cfg.Fluently.Configure()
C:\Projects\highoncodingmvc\src\highoncoding\src\HighOnCoding.BusinessObjects\Factories\SessionFactory.cs(17,0): at HighOnCoding.BusinessObjects.Factories.SessionFactory.CreateSessionFactory()
C:\Projects\highoncodingmvc\src\highoncoding\src\HighOnCoding.TestSuite\Configuration\TestFluentNHiberate.cs(17,0): at HighOnCoding.TestSuite.Configuration.when_instantiating_a_session_factory.should_be_able_to_create_a_session_factory()
Inner Exception
System.IO.FileLoadException
Message: The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source: NHibernate
StackTrace:
at NHibernate.Cfg.Configuration..cctor()

Here is the log information from FusionLog thing:

* Assembly Binder Log Entry (6/21/2009 @ 12:49:38 PM) *

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable C:\Projects\highoncodingmvc\src\highoncoding\src\HighOnCodingConsole\bin\Debug\HighOnCodingConsole.exe
— A detailed error log follows.

=== Pre-bind state information ===
LOG: User = D9SKQBG1\AzamSharp
LOG: DisplayName = NHibernate.XmlSerializers, Version=2.0.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL
(Fully-specified)
LOG: Appbase = file:///C:/Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL

Calling assembly : System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\highoncodingmvc\src\highoncoding\src\HighOnCodingConsole\bin\Debug\HighOnCodingConsole.exe.Config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: NHibernate.XmlSerializers, Version=2.0.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///C:/Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers/NHibernate.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///C:/Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers.EXE.
LOG: Attempting download of new URL file:///C:/Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers/NHibernate.XmlSerializers.EXE.
LOG: All probing URLs attempted and failed.

Best Answer

Looks like you've compiled against one version of an assembly, but at execution time it's finding another and complaining. I suggest you turn on Fusion logging to work out what's going on - in particular, the exact assembly which is causing problems!

Related Topic