尝试运行Fluent NHibernate教程示例时出现运行时错误(Runtime error when trying to run Fluent NHibernate tutorial example)

我在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文件夹。 基于googling的错误,我设置了对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中。

对于我的生活,我无法弄清楚问题所在。 我尝试了所有我能想到的,并搜索了多个错误消息,但没有为我工作。

帮帮我! 我在这方面浪费了几个小时。

编辑 我已经把项目的源文件放在http://dl.dropbox.com/u/8824836/FluentNHibernateExample.zip 。 请记住,要完全复制我的环境,您需要将来自这里的所有文件放到output / 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

最满意答案

我觉得这是一个白痴,但在一天结束时,映射问题是由于我已经命名项目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

更多推荐