views:

113

answers:

4

Hello,

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

A: 

You may also need:

  • Castle.Core.dll
  • Castle.DynamicProxy2.dll
anthony
Thanks for your suggestion. As mentioned, since those files are in the fluent-nhibernate download zip...they were already added to my bin folder. However, per your suggestion I added references in my project to those files. But I am getting the same result. Seth
Seth Spearman
A: 

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.

Bevan
+1  A: 

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.

James Gregory
JamesI was thinking that very thing but I could not find a way to get the source without git. I am still on svn. I can get git (hehe) since it is tiny but was wondering if there was a way to get the source without it?
Seth Spearman
Seth, it's 2010, do yourself a favor and download a git client. Tortoise (GUI) http://code.google.com/p/tortoisegit/ or msysgit (command line) http://code.google.com/p/msysgit/
anthony
Seth: [fluentnhibernate.org/downloads](http://fluentnhibernate.org/downloads) has them at the bottom on the right; they're only for individual builds though, and not specific releases. If you want the source specifically for 1.1, Github allows you to download a zip of a tag in the [downloads section for a repo](http://github.com/jagregory/fluent-nhibernate/downloads).
James Gregory
A: 

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

Seth Spearman