尝试运行Fluent NHibernate教程示例时出现运行时错误

我在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()) .ExposeConfiguration(BuildSchema) .BuildSessionFactory(); } 

我认为最有帮助的事情是给你从最外层exception到最内层exception的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) 

该教程不清楚如何设置引用(或者至少基于最内部的exception看起来不完整)所以我从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目录中。

赛斯

我觉得这是一个白痴,但最终映射问题是由于我将项目命名为FluentNHibernate(在我自己的防御中它位于SAMPLES文件夹中),但这导致映射失败。

在内部,Visual Studio将程序集名称默认为FluentNHibernate,这导致运行时错误。 将程序集重命名为ConsoleApplication修复它。

赛斯

下载Fluent NHibernate源代码分发,然后看一下示例项目; 然后,您可以将这些项目的引用与您的项目进行比较。

您可能还需要:

  • Castle.Core.dll
  • Castle.DynamicProxy2.dll

仅仅因为您的流畅NHibernate项目编译 ,这并不意味着您的映射是正确的。

外部exception(与FluentNHibernate组件有关,可能是红色鲱鱼)。

尝试注释掉你所有的nhibernate映射,除了最简单,最简单的一点 – 然后看它是否有效。 如果是这样的话,逐渐取消注释,直到找到失败的位。