我在http://wiki.fluentnhibernate.org/Getting_started上完成了 Fluent NHibernate 教程,项目编译良好。
但是,我遇到了运行时错误,我似乎无法解决它。您可以在教程中看到的 CreateSessionFactory 方法中发生错误。这里是:
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database
(
SQLiteConfiguration.Standard
.UsingFile(DbFile)
)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<FluentNHibernateSample.Program>())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
我认为最有帮助的事情是为您提供从最外层异常到最内层异常的异常链(这是一个真实的词):
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
Could not compile the mapping document: (XmlDocument)
persistent class FluentNHibernateSample.Entities.Employee, FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null not found
Could not load file or assembly 'FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
本教程不清楚如何设置参考(或者至少基于最内部的异常似乎不完整)所以我从http://fluentnhibernate.org/downloads/releases/fluentnhibernate-1.1.zip获得了编译的程序集并复制了将它们放入 libs 文件夹中。基于谷歌搜索错误,我设置了对 FluentNHibernate、NHibernate 和 NHibernate.ByteCode.Castle 程序集的引用。我将下载页面中的所有 dll 复制到 bin 目录中,我认为所有引用都会解决。(这是我对其工作原理的理解)。无论如何,这里是我复制到 bin 中的文件列表。
Antlr3.Runtime.dll
FluentNHibernate.dll
FluentNHibernate.exe
FluentNHibernate.pdb
FluentNHibernate.vshost.exe
FluentNHibernate.vshost.exe.manifest
FluentNHibernate.xml
Iesi.Collections.dll
Iesi.Collections.xml
log4net.dll
log4net.xml
NHibernate.ByteCode.Castle.dll
NHibernate.dll
NHibernate.xml
我还将 System.Data.Sqlite 程序集复制到了 bin。
对于我的生活,我无法弄清楚问题是什么。我已经尝试了所有我能想到的方法,并在 Google 上搜索了多条错误消息,但对我没有任何帮助。
帮助!我在这上面浪费了几个小时。
编辑
我已将项目的源文件放在http://dl.dropbox.com/u/8824836/FluentNHibernateExample.zip。请记住,要完全复制我的环境,您需要将此处的所有文件放入您的 output/bin 目录。
赛斯