我完成了 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 程序集复制到垃圾箱中。
对于我的一生,我无法弄清楚问题是什么。我已经尝试了我能想到的一切,并用谷歌搜索了多个错误消息,但没有任何效果对我有用。
帮助!我在这上面浪费了几个小时。
编辑
我已将该项目的源文件放在 http://dl.dropbox.com/ u/8824836/FluentNHibernateExample.zip。请记住,要完全复制我的环境,您需要将所有文件从此处< /a> 进入您的输出/bin 目录。
赛斯
I worked through the Fluent NHibernate tutorial at http://wiki.fluentnhibernate.org/Getting_started and the project compiles fine.
However, I am getting a runtime error and I can't seem to resolve it. The error is happening in the CreateSessionFactory method you can see in the tutorial. Here it is:
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database
(
SQLiteConfiguration.Standard
.UsingFile(DbFile)
)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<FluentNHibernateSample.Program>())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
I think the most helpfule thing to do is to give you the Exception chain (is that a real word) from the Outermost exception to the inner most exception:
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)
The tutorial was not clear on how to setup the reference (or at least seems incomplete based on the most inner exception) so I got the compiled assemblies from http://fluentnhibernate.org/downloads/releases/fluentnhibernate-1.1.zip and copied them into a libs folder. Based on googling the error I set a references to the FluentNHibernate, NHibernate, and NHibernate.ByteCode.Castle assemblies. I copied ALL of the dlls from the downloads page into the bin directory and I thought that all of the references would resolve. (That is my understanding of how it works). In any case here is the list of files I copied into 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
I also copied System.Data.Sqlite assembly to the bin.
For the life of me I cannot figure out what the problem is. I have tried everything I can think of and googled multiple error messages but nothing has worked for me.
Help! I have wasted hours on this.
EDIT
I have put the source files for the project at http://dl.dropbox.com/u/8824836/FluentNHibernateExample.zip. Keep in mind that to fully replicate my environment you need to put all of the files from here into your output/bin directory.
Seth
发布评论
评论(4)
我觉得自己像个白痴,但归根结底,映射问题是由于我将项目命名为 FluentNHibernate (在我自己的辩护中,它位于 SAMPLES 文件夹中),但这导致映射失败。
在内部,Visual Studio 将程序集名称默认为 FluentNHibernate,这导致了运行时错误。将程序集重命名为 ConsoleApplication 修复了该问题。
赛斯
I feel like an idiot for this but at the end of the day the mapping problem was caused by the fact that I had named the project FluentNHibernate (in my own defense it was in a SAMPLES folder) but that was causing the mapping to fail.
Internally Visual Studio defaulted the Assembly name to FluentNHibernate and that was causing the runtime error. Renaming the assembly to ConsoleApplication fixed it.
Seth
下载 Fluent NHibernate 源代码发行版,然后查看示例项目;然后,您可以将这些项目的参考文献与您的项目的参考文献进行比较。
Download the Fluent NHibernate source distribution, then take a look at the example projects; you can then compare the references those projects have to the ones yours has.
您可能还需要:
You may also need:
仅仅因为您流畅的 NHibernate 项目可以编译,并不意味着您的映射是正确的。
外部异常(与 FluentNHibernate 程序集有关可能是转移注意力的事情)。
尝试注释掉除最简单、最容易的部分之外的所有 nhibernate 映射 - 然后看看它是否有效。如果确实如此,请逐渐取消注释,直到找到失败的部分。
Just because your fluent NHibernate project compiles, that doesn't mean that your mapping is correct.
The outer exception (to do with the
FluentNHibernate
assembly could be a red herring).Try commenting out all of your nhibernate mapping except the simplest, easiest bit - and see if it works then. If it does, gradually uncomment things until you find the bit that fails.