views:

1475

answers:

3

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?

A: 

I'm unable to observe this behavior in my build, could it be related to this problem: http://stackoverflow.com/questions/1924814/weird-override-problem-with-fluent-nhibernate-and-net-4

If so you could try http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/ae4013d711d2e4ad as a potential fix.

KeeperOfTheSoul
Yeah - you'll notice that the other SO post you linked to was also created by me. They are maybe related in that they both spawn from trying to run FNH on .NET 4, but the specific problems are distinct.
Tomas Lycken
I was thinking perhaps it was reflecting over the types for intellisense or something and running into the same error.
KeeperOfTheSoul
You were right - when I did solve the other problem, this worked as well.
Tomas Lycken
+4  A: 

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.

Alper
A: 

Isn't there a better way to fix this problem?

I don't want to reference System.Data.OracleClient. So I shouldn't have to target the full .Net framework if I don't even want that reference.

Can't I target the Client Profile of the .Net framework, but add a compiler warning exception somewhere so that it just skips that warning? I know it won't cause a runtime problem because I don't use Oracle.

I get identical problem which says there's also a dependency on System.Web. Same story, this is for a Windows WPF app, so I don't need System.Web. Can't I just target the Client Profile and somehow convince the compiler to keep going?

Thanks, Hugh

EDIT: I figured this out! I had to compile NHibernate myself though. Opened the 2.1.2 code in Visual Studio and deleted everything that says "Oracle" or "System.Web" and I ended up getting it to build. I do not have to target the full .Net Framework now.

HugeHugh