2011-02-01 67 views
5

我已经hibernate.cfg.xml文件包括在我的WCF服务库NHibernate的 - 无法找到hibernate.cfg.xml文件

BuildAction = Content and 
Copy to output directory = Copy Always

然而,当我运行应用程序它抛出以下错误:

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

我不知道为什么它在上面的路径而不是运行时bin目录寻找hibernate.cfg.xml。

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

任何想法?

回答

14

一种选择是将你的NHibernate的配置到web.config中

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

在你configsections部分添加

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

另一种选择是尝试这种(WCF中未经测试)

var cfg = new Configuration(); 
cfg.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"hibernate.cfg.xml")); 
+0

感谢Rippo,设置Environment.CurrentDirectory = System.AppDomain.CurrentDomain.Ba seDirectory;解决了我的问题。但是我仍然无法理解为什么运行时将DevExpress作为当前目录。 – iniki 2011-02-01 10:21:14