Nhibernate 用 App.Config 配置 出错

报错内容如下:Thetypeinitializerfor'NHibernate.Cfg.Environment'threwanexception.InnerExcepti... 报错内容如下:
The type initializer for 'NHibernate.Cfg.Environment' threw an exception.
InnerExceptino:
An error occurred creating the configuration section handler for hibernate-configuration: Could not load file or assembly 'NHibernate' or one of its dependencies. The system cannot find the file specified. (C:\\...(路径省略)\\Console1\\Console1\\bin\\Debug\\Console1.vshost.exe.config line 6)
-------------------------------------------
app.config配置文件如下:
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">
Data Source=.;Initial Catalog=NHibernate;
Integrated Security=True;Pooling=False
</property>
<property name="adonet.batch_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="use_outer_join">true</property>
<property name="command_timeout">10</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
</session-factory>
</hibernate-configuration>
</configuration>
----------------------------------
程序如下:
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;

namespace Console1
{
class Program
{
static void Main(string[] args)
{
Configuration config = new Configuration();//在这里就会报错
}
}
}
---------------------------------
我的Nhibernate版本是2.0.1.4000
---------------------------------
先谢过啦!
报错的InnerException中:"line 6"所指的就是
{<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />}这一行
我使用hibernate.cfg.xml文件配置就可以通过...内容如下:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">
Data Source=.;Initial Catalog=NHibernate;
Integrated Security=True;Pooling=False
</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
... ...
</session-factory>
</hibernate-configuration>
但是还是想弄明白:为什么用App.config这种配置方法会出错啊
展开
 我来答
亥男056
2010-03-11 · TA获得超过102个赞
知道小有建树答主
回答量:300
采纳率:0%
帮助的人:22万
展开全部
应该不是配置文件问题,而是你的NHibernate安装问题,缺少某个文件,或者该文件的权限由问题
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式