'NHibernate.Cfg.Configuration'的类型初始化程序引发了异常

时间:2009-06-21 17:34:20

标签: fluent-nhibernate

我正在使用FluentNHibernate,在配置阶段我收到以下错误:

以下是配置:

public static ISessionFactory CreateSessionFactory()         {             返回                 Fluently.Configure()。数据库(                     MsSqlConfiguration.MsSql2000.ConnectionString(                         c => c.FromConnectionStringWithKey( “HighOnCodingConnectionString”)))                         .Mappings(m =>
      m.FluentMappings.AddFromAssemblyOf())       .BuildSessionFactory();         }

这是错误:

[失败] when_instantiating_a_session_factory.should_be_able_to_create_a_session_factory TestCase'while_instantiating_a_session_factory.should_be_able_to_create_a_session_factory' 失败:'NHibernate.Cfg.Configuration'的类型初始化程序引发了异常。     System.TypeInitializationException     消息:'NHibernate.Cfg.Configuration'的类型初始值设定项引发了异常。     资料来源:NHibernate     堆栈跟踪:     在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()     内在例外     System.IO.FileLoadException     消息:定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)     资料来源:NHibernate     堆栈跟踪:     在NHibernate.Cfg.Configuration..cctor()

这是来自FusionLog的日志信息:

*装配活页夹日志条目(6/21/2009 @ 12:49:38 PM)*

操作失败。 绑定结果:hr = 0x80070002。系统找不到指定的文件。

程序集管理器从:c:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ mscorwks.dll加载 在可执行文件C:\ Projects \ highoncodingmvc \ src \ highoncoding \ src \ HighOnCodingConsole \ bin \ Debug \ HighOnCodingConsole.exe下运行 ---详细的错误日志如下。

===预绑定状态信息=== 日志:用户= D9SKQBG1 \ AzamSharp 日志:DisplayName = NHibernate.XmlSerializers,Version = 2.0.1.4000,Culture = neutral,PublicKeyToken = aa95f207798dfdb4,processorArchitecture = MSIL  (完全指定的) 日志:Appbase = file:/// C:/ Projects / highoncodingmvc / src / highoncoding / src / HighOnCodingConsole / bin / Debug / 日志:初始PrivatePath = NULL 日志:动态Base = NULL 日志:缓存基数= NULL 日志:AppName = NULL

调用程序集:System.Xml,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089。

日志:此绑定在默认加载上下文中启动。 日志:使用应用程序配置文件:C:\ Projects \ highoncodingmvc \ src \ highoncoding \ src \ HighOnCodingConsole \ bin \ Debug \ HighOnCodingConsole.exe.Config 日志:使用c:\​​ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ config \ machine.config中的计算机配置文件。 日志:政策后参考:NHibernate.XmlSerializers,Version = 2.0.1.4000,Culture = neutral,PublicKeyToken = aa95f207798dfdb4,processorArchitecture = MSIL 日志:GAC Lookup未成功。 日志:尝试下载新的URL文件:/// C:/Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers.DLL。 日志:尝试下载新的URL文件:/// C:/Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers/NHibernate.XmlSerializers.DLL。 日志:尝试下载新的URL文件:/// C:/Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers.EXE。 日志:尝试下载新的URL文件:/// C:/Projects/highoncodingmvc/src/highoncoding/src/HighOnCodingConsole/bin/Debug/NHibernate.XmlSerializers/NHibernate.XmlSerializers.EXE。 日志:所有探测URL都已尝试失败。

2 个答案:

答案 0 :(得分:2)

看起来你已经针对一个版本的程序集进行了编译,但是在执行时它正在寻找另一个版本并抱怨。我建议你turn on Fusion logging弄清楚发生了什么 - 特别是导致问题的确切装配!

答案 1 :(得分:2)

我知道这已经解决了很久,但是我今天遇到了这个问题,我发现这是我个人的解决方案,并且认为我会分享这些知识:

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

来自帖子:

“Visual Studio中的调试器设置为中断所有异常,调整异常设置解决了我的问题。”

还引导我:

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

“经过一些搜索后,我发现xxxx.XmlSerializers程序集是xmlserializers在尝试在运行时生成一个之前查找的预生成程序集......”