问题NHibernate,Fluent NHibernate和Iesi.Collection。 接下来你会尝试什么?

我对NHibernate非常陌生,所以如果我在这里遗漏了一些微不足道的话我会道歉。 我目前正在编写一本名为“NHibernate 3初学者指南”的书,来自packtpub。 我大多数都遵循书中的指示。 当我说大多数情况下,我已经使用MySQL而不是MSSQL,并且一直在使用NuGet,而不是手动下载二进制文件。

我现在在第2章,这是第一个真正的编码章节。 在本章中,我将构建一个简单的WPF应用程序,通过单击按钮来构建我的数据库模式。 我已经为本章中指定的ProductCategory类构建了一些POCO。 通过NuGet我添加了以下参考:

  1. MySQL.Data
  2. NHibernate(作为依赖自动解析,Iesi.Collections)
  3. 流利的NHibernate

当我单击按钮构建我的数据库时,执行以下代码块:

 private const string connString = "string omitted for brevity"; private void btnCreateDatabase_Click(object sender, RoutedEventArgs e) { Fluently.Configure().Database(MySQLConfiguration.Standard.ConnectionString(connString)) .Mappings(m => m.FluentMappings.AddFromAssemblyOf()) .ExposeConfiguration(CreateSchema) .BuildConfiguration(); } 

单击按钮后,我收到以下exception( FileLoadException ):

外部exception消息: Could not load file or assembly 'Iesi.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Could not load file or assembly 'Iesi.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

内部exception消息: Could not load file or assembly 'Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Could not load file or assembly 'Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

如果有帮助,这是“Fusion Log”:

 === Pre-bind state information === LOG: User = Borealis\Frito LOG: DisplayName = Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4 (Fully-specified) LOG: Appbase = file:///C:/Users/Frito/documents/visual studio 2010/Projects/NH3BeginnersGuide/Chapter2/App/Sample.UI/bin/Debug/ LOG: Initial PrivatePath = NULL Calling assembly : NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\Frito\documents\visual studio 2010\Projects\NH3BeginnersGuide\Chapter2\App\Sample.UI\bin\Debug\Sample.UI.vshost.exe.config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Redirect found in application configuration file: 1.0.1.0 redirected to 4.0.0.0. LOG: Post-policy reference: Iesi.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4 LOG: Attempting download of new URL file:///C:/Users/Frito/documents/visual studio 2010/Projects/NH3BeginnersGuide/Chapter2/App/Sample.UI/bin/Debug/Iesi.Collections.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated. 

我尝试了以下内容,现在有点不知所措:

  1. 试图通过NuGet升级Iesi.Collections但是没有说NHibernate没有兼容的版本。
  2. 下载NHibernate和FluentNhibernate的二进制文件并手动引用它们。
  3. 从书中提取源样本并复制样本中的DLL。 这给了我一个不同的错误,我还没有进行足够的研究来提问。

我有两个问题:

  1. 首先,为什么当发布的版本指向1时,NuGet包会尝试查找版本4. * dll。*?
  2. 我还应该尝试哪些其他方法来获取所有来源并在本地构建? 我有点失落,并且会喜欢其他一些输入。

提前致谢!

神圣的蠢货让我疯狂。 我发现app.config是在某个时候创建​​的,大概就是因为我搞砸了什么。 在app.config我发现了以下内容:

            

注释掉Runtime元素,重建和运行允许上面的按钮正常运行。 我不知道我做了什么导致它生成但我很高兴我找到了它。 感谢所有人为您的努力提供帮助,并感谢您对该问题的支持!

Iesi.Collections 4.0是一个针对.Net 4.0的大量修改版本,用于未来的NHibernate 4.0。

不幸的是,NHibernate版本(包括3.3.1版本)的Nuget包不指定Iesi依赖项的上限。 随着NHibernate 3.3.2的改变,明确禁止Iesi版本4或更高版本。 因此,如果您通过NuGet更新到NH 3.3.2,我希望它将Iesi依赖关系解析为3.x版本。