我对NHibernate非常陌生,所以如果我在这里遗漏了一些小事,我会道歉。我目前正在编写一本名为“NHibernate 3初学者指南”的书,来自packtpub。我大多数都遵循书中的指示。当我说大多数情况下,我已经使用MySQL而不是MSSQL,并且一直在使用NuGet,而不是手动下载二进制文件。
我现在在第2章,这是第一个真正的编码章节。在本章中,我将构建一个简单的WPF应用程序,通过单击按钮来构建我的数据库模式。我已经为本章中指定的Product
和Category
类构建了一些POCO。通过NuGet,我添加了以下参考文献:
当我单击按钮构建我的数据库时,执行以下代码块:
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<ProductMap>())
.ExposeConfiguration(CreateSchema)
.BuildConfiguration();
}
单击按钮后,我收到以下异常(FileLoadException
):
外部异常消息: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=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.
我尝试了以下内容,现在有点不知所措:
我有两个问题:
提前致谢!
答案 0 :(得分:35)
神圣的蠢货让我疯了。我发现在某个时刻创建了一个app.config
,大概就是因为我在弄乱某些东西。在app.config
我找到了以下内容:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Iesi.Collections" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
注释掉Runtime
元素,重建和运行允许上面的按钮正常运行。我不知道我做了什么导致这个产生,但我很高兴我找到了它。感谢所有人为此提供的帮助和感谢,感谢您对此问题的支持!
答案 1 :(得分:16)
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版本。