Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Fluent NHibernate with .NET 4.0?

I want to learn to use Fluent NHibernate, and I'm working in VS2010 Beta2, compiling against .NET 4, but I'm experiencing some problems.

Summary
My main problem (at the moment) is that the namespace FluentNHibernate isn't available even though I've imported all the .dll assemblies mentioned in this guide.

This is what I've done:
1. I downloaded the Fluent NHibernate source from here, extracted the .zip and opened the solution in VS. A dialog asked me if I wanted to convert the solution to a VS2010 solution, so I did.
2. I then went into each project's properties and configured all of them to compile for .NET 4, and built the entire solution.
3. I copied all the .dll files from /bin/Debug/ in the FluentNHibernate to a new folder on my local hard drive.
4. In my example project, I referenced FluentNHibernate.dll and NHibernate.dll from the new folder.

This is my problem:
If I right-click on FluentNHibernate in the References list and select "View in Object Browser...", it shows up correctly.

Now, when I try to create a mapping class, I can't import FluentNHibernate. This code:

using FluentNHibernate.Mapping;

namespace FluentNHExample.Mappings
{

}

generates an error on the using statement, saying

The type or namespace 'FluentNHibernate' could not be found (are you missing a using directive or an assembly reference?).

The FluentNHibernate assembly is still in the list of References of my project, but if I try to browse the assembly in Object Browser again, it can't be found.

What is causing this?

like image 504
Tomas Aschan Avatar asked Dec 17 '09 16:12

Tomas Aschan


1 Answers

I also had similar problem.

"Error List" window displayed:

The type or namespace name 'FluentNHibernate' could not be found (are you missing a using directive or an assembly reference?)

But "Output" window was displaying detailed information:

warning MSB3253: The referenced assembly "FluentNHibernate" could not be resolved because it has a dependency on "System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.

In my case; I had created a console application project which was targeting ".Net Framework 4 Client Profile" by default, so changing to ".Net Framework 4" fixed issue for me.

like image 75
Alper Avatar answered Oct 11 '22 05:10

Alper