NHibernate-找不到文件hibernate.cfg.xml

NHibernate-找不到文件hibernate.cfg.xml,nhibernate,Nhibernate,我的WCF服务库中包含了hibernate.cfg.xml和 BuildAction = Content and Copy to output directory = Copy Always BuildAction=Content和 复制到输出目录=始终复制 但是,当我运行应用程序时,它抛出以下错误: Could not find file 'C:\Program Files (x86)\DevExpress 2010.2\IDETools\System\CodeRush\Bin\Plug

我的WCF服务库中包含了hibernate.cfg.xml和

BuildAction = Content and Copy to output directory = Copy Always BuildAction=Content和 复制到输出目录=始终复制 但是,当我运行应用程序时,它抛出以下错误:

Could not find file 'C:\Program Files (x86)\DevExpress 2010.2\IDETools\System\CodeRush\Bin\PlugIns\hibernate.cfg.xml' 找不到文件 'C:\ProgramFiles(x86)\DevExpress 2010.2\IDETools\System\coderash\Bin\PlugIns\hibernate.cfg.xml' 我不确定它为什么在上面的路径而不是运行时bin目录中查找hibernate.cfg.xml

仅供参考:我最近安装了DevExpress v10.2,用于其他应用程序


有什么想法吗?

一个选项是将您的nHibernate配置移动到web.config中

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    ...
  </session-factory>
</hibernate-configuration>
另一种选择是尝试此方法(未在wcf中测试)


感谢Rippo,设置Environment.CurrentDirectory=System.AppDomain.CurrentDomain.BaseDirectory;解决了我的问题。但是,我仍然无法理解为什么运行时将DevExpress作为当前目录。尽管如此,最好明确告诉NHibernate配置在哪里可以找到配置xml。使用WCF服务应用程序而不是库,我发现需要在文件名前加上前缀“bin/”。由于无论如何在部署时程序集都会在bin文件夹中,我认为这种硬编码不会有问题。
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" requirePermission="false" />
    ...
  <configSections>
<configuration>
var cfg = new Configuration();
cfg.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"hibernate.cfg.xml"));