views:

2032

answers:

1

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.

A: 

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!

Jon Skeet
But how is that possible! I just got the DLL's from FluentNHibernate website and added reference to all the assemblies manually!
azamsharp
It may be loading an assembly from the GAC at execution time. The best way to find out is to use fusion logging...
Jon Skeet
The strange thing is that I just added a Console Application and use the same code for setting up the session factory and it worked fine with no errors.
azamsharp
I have edited the original post to include the log information from Fusion. Seems like the culprit is NHibernate.XmlSerializers but this assembly is not included by the FluentNHibernate download!
azamsharp
I also tried the code to insert into the database and it worked for a Console Application without any trouble!
azamsharp
Weird thing again!!! I just removed all the assemblies from the test project except the NHibernate and then it worked fine and the test passed! This problem should be documented by the FluentNHibernate team!
azamsharp

related questions