views:

586

answers:

2

Hi,

I have a class library with all my nhibernate code (domain/mappings using fluent).

Now I am just doing some simple tests in a console application, and I am getting an error saying it can't find the configruation file in /bin/debug

I have the file in /consoleTests/hibernate.cfg.xml

Why would it be looking in the /bin/debug folder of the console application?

A: 

That's the current directory when running in Visual Studio. Is that what you're doing?

Eric J.
what do you mean? I am just running the console application from within vs.net....
mrblah
@Homestead: Adrianbanks gave the full answer to that.
Eric J.
+4  A: 

If you are calling the Configure() method without any parameters, then I believe that the hibernate.cfg.xml must be in the same directory as the application that uses it.

When you compile your project, it gets compiled to the bin/debug/ directory. When you run your project (by either clicking on it or debugging it in Visual Studio), the working directory is bin/debug/, so that is where the hibernate.cfg.xml file is expected to be.

You could:

  • use a post-build event within Visual Studio to copy the hibernate.cfg.xml file to the output directory
  • call Configure(path), where path is the path to your hibernate.cfg.xml in your /consoleTests/ directory.

Have a look at "A fluent interface to NHibernate - Part 4 - Configuration" for more detailed information on how to configure NHibernate.

adrianbanks
Change the properties for the hibernate.cfg.xml to "copy always" or "copy if newer" and it will be copied to the output path.
Simon Svensson