The type initializer for "NHibernate.Cfg.Configuration" threw an exception

I am using FluentNHibernate and at the configuration stage I get 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: type initializer for "NHibernate.CfgC made. System.TypeInitializationException Message: The type initializer for "NHibernate.Cfg.Configuration" made an exception. Source: NHibernate Stack Traces: in NHibernate.Cfg.Configuration..ctor () c: \ FluentNHibernate \ src \ FluentNHibernate \ Cfg \ FluentConfiguration.cs (25.0): on 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 \ Factory (17.0): with HighOnCoding.BusinessObjects.Factories.SessionFactory.CreateSessionFactory () C: \ Projects \ highoncodingmvc \ src \ highoncoding \ src \ HighOnCoding.TestSuite \ Configuration \ TestFluentNHiberate.cs (17.0): with HighOSuCite.Test .Configuration.when_instantiating_a_session_factory.should_be_able_to_create_a_session_factory () Internal exception System.IO.FileLoadException Message: The located manifest definition of the assembly does not match uet assembly reference. (Exception from HRESULT: 0x80131040) Source: NHibernate Stack Traces: in NHibernate.Cfg.Configuration..cctor ()

Here is the log information from FusionLog:

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

The operation failed. Binding Result: hr = 0x80070002. The system cannot find the specified file.

The build manager was downloaded from: c: \ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ mscorwks.dll Run under the executable file C: \ Projects \ highoncodingmvc \ src \ highoncoding \ src \ HighOnCodingConsole \ bin \ Debug \ HighOnCodingConsole.exe - - The following is a detailed error log.

=== Prebinding status 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

Assembly call: System.Xml, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089.

LOG: this binding starts in the context of the default load. LOG: Using the application configuration file: C: \ Projects \ highoncodingmvc \ src \ highoncoding \ src \ HighOnCodingConsole \ bin \ Debug \ HighOnCodingConsole.exe.Config LOG: Using the machine configuration file from c: \ WINDOWS \ Microsoft.NET \ Framework \ v2 .0.50727 \ config \ machine.config. LOG: Post-policy link: NHibernate.XmlSerializers, Version = 2.0.1.4000, Culture = neutral, PublicKeyToken = aa95f207798dfdb4, processorArchitecture = MSIL LOG: The search in the GAC was unsuccessful. LOG: attempt to load a new file URL: /// C: /Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers.DLL. LOG: attempt to load a new file URL: /// C: /Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers/NHibernate.XmlSerializers.DLL. LOG: attempt to load a new file URL: /// C: /Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers.EXE. LOG: attempt to load a new file URL: /// C: /Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers/NHibernate.XmlSerializers.EXE. LOG: all trial URLs were tried and failed.

+4
source share
2 answers

It looks like you have assembled against one version of the assembly, but at run time it finds another and complains. I suggest you turn on Fusion logging to find out what happens - in particular, the exact build that causes the problems!

+2
source

I know that this was resolved long ago, but today, when I had this problem, I found it with my personal solution and thought that I was sharing knowledge:

https://forum.hibernate.org/viewtopic.php?p=2399679

From the post:

"My debugger in Visual Studio was set to break in all exceptions, setting the exception options fixed my problem."

Also led me to:

http://www.codewrecks.com/blog/index.php/2008/02/13/sgenexe-and-strongly-named-assemblies/

"After some searching, I found that the assembly xxxx.XmlSerializers is the pre-generated assembly that xmlserializers looks for before trying to generate it at runtime ..."

+2
source

Source: https://habr.com/ru/post/1286542/


All Articles