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这种配置方法会出错啊 展开
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这种配置方法会出错啊 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询