简体   繁体   English

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

[英]Runtime error when trying to run Fluent NHibernate tutorial example

I worked through the Fluent NHibernate tutorial at http://wiki.fluentnhibernate.org/Getting_started and the project compiles fine. 我在http://wiki.fluentnhibernate.org/Getting_started上的Fluent NHibernate教程中进行了工作,项目编译正常。

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. 您可以在本教程中看到的CreateSessionFactory方法中发生了错误。 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. 本教程尚不清楚如何设置引用(或者至少根据最内部的异常似乎不完整),因此我从http://fluentnhibernate.org/downloads/releases/fluentnhibernate-1.1.zip获取了已编译的程序集并进行了复制将它们放入libs文件夹。 Based on googling the error I set a references to the FluentNHibernate, NHibernate, and NHibernate.ByteCode.Castle assemblies. 基于搜索错误,我设置了对FluentNHibernate,NHibernate和NHibernate.ByteCode.Castle程序集的引用。 I copied ALL of the dlls from the downloads page into the bin directory and I thought that all of the references would resolve. 我将所有dll从下载页面复制到bin目录中,我认为所有引用都可以解决。 (That is my understanding of how it works). (这是我对它如何工作的理解)。 In any case here is the list of files I copied into 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

I also copied System.Data.Sqlite assembly to the bin. 我还将System.Data.Sqlite程序集复制到了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 . 我将项目的源文件放在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. 请记住,要完全复制我的环境,您需要将此处的所有文件放入您的output / bin目录。

Seth 赛斯

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. 我觉得这很愚蠢,但是最终,映射问题是由于我将项目命名为FluentNHibernate(以我的辩护,它在SAMPLES文件夹中)而引起的,但是这导致了映射失败。

Internally Visual Studio defaulted the Assembly name to FluentNHibernate and that was causing the runtime error. 在Visual Studio内部,程序集名称默认为FluentNHibernate,这会导致运行时错误。 Renaming the assembly to ConsoleApplication fixed it. 将程序集重命名为ConsoleApplication可以修复它。

Seth 赛斯

Download the Fluent NHibernate source distribution, then take a look at the example projects; 下载Fluent NHibernate源代码发行版,然后看一下示例项目。 you can then compare the references those projects have to the ones yours has. 然后,您可以将这些项目的引用与您的项目进行比较。

You may also need: 您可能还需要:

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

Just because your fluent NHibernate project compiles , that doesn't mean that your mapping is correct. 仅仅因为您能熟练使用NHibernate项目进行编译 ,并不意味着您的映射是正确的。

The outer exception (to do with the FluentNHibernate assembly could be a red herring). 外部异常(与FluentNHibernate程序集有关的可能是红色鲱鱼)。

Try commenting out all of your nhibernate mapping except the simplest, easiest bit - and see if it works then. 尝试注释掉所有最简单,最简单的位以外的所有nhibernate映射-然后查看它是否有效。 If it does, gradually uncomment things until you find the bit that fails. 如果是这样,请逐渐取消注释,直到找到失败的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM