Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate - Could not find file hibernate.cfg.xml

Tags:

nhibernate

I have hibernate.cfg.xml included in my WCF service library with

BuildAction = Content and   
Copy to output directory = Copy Always

However, when I run the application it is throwing following error:

Could not find file
'C:\Program Files (x86)\DevExpress 2010.2\IDETools\System\CodeRush\Bin\PlugIns\hibernate.cfg.xml'

I am not sure why it is looking for hibernate.cfg.xml at above path instead of run-time bin directory.

FYI: I have recently installed DevExpress v10.2 to be used in another application.

Any ideas?

like image 370
inutan Avatar asked Feb 01 '11 06:02

inutan


1 Answers

One option is to move your nHibernate configuration into the web.config

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    ...
  </session-factory>
</hibernate-configuration>

In your configsections section add

<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" requirePermission="false" />
    ...
  <configSections>
<configuration>

Another option is to try this (untested in wcf)

var cfg = new Configuration();
cfg.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"hibernate.cfg.xml"));
like image 174
Rippo Avatar answered Oct 02 '22 22:10

Rippo