2011-04-12 67 views
0

我设置了一个hibernate项目,并且一直在收到代理错误。我已经将Castle引用添加到了我的项目中。我的web.config中有以下几点:nhibernate web.config问题

<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/> 
</configSections> 

<nhibernate xmlns="urn:nhibernate-configuration-2.2"> 
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
    <property name="connection.connection_string">Data Source=192.168.1.100, 0000;Initial Catalog=GDER;Persist Security Info=True;User ID=re;Password=none12</property> 
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> 
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> 
</nhibernate> 

然而,我收到以下错误一贯

没有配置的ProxyFactoryFactory。使用其中一个可用的NHibernate.ByteCode提供程序初始化会话工厂配置部分的'proxyfactory.factory_class'属性。例如:NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu例如:NHibernate.ByteCode.Castle.ProxyFactoryFactory,> NHibernate.ByteCode.Castle

调试总是失败这里(NHibernate.ISessionFactory factory = config.BuildSessionFactory();):

NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); 
// add our assembly 
config.AddAssembly("nHibernateTest"); 
// setup nhibernate session 
NHibernate.ISessionFactory factory = config.BuildSessionFactory(); 
NHibernate.ISession session = factory.OpenSession(); 
// start nhibernate transaction 
NHibernate.ITransaction transaction = session.BeginTransaction(); 

请帮助...

+2

使用4个空格缩进代码的每一行以使其正确显示。你也需要格式化你的web.config文件,以便它的可读性。你应该能够找到如何做到这一点[这里](http://stackoverflow.com/editing-help)。很难像现在这样阅读。 – 2011-04-12 16:47:55

回答

1

你还需要在你的项目添加到代理提供一个参考(项目>添加引用...并选择NHibernate.ByteCode.Castle.dll)。

+0

我这样做没有成功 – James 2011-04-12 20:39:37

+2

@詹姆斯,你有没有验证NHibernate.ByteCode.Castle.dll被复制到你的部署文件夹? – Graham 2011-04-12 20:45:11

1

在添加程序集之前,您错过了对config.Configure()的调用。

+0

+1。 “NHibernate in Action”一书在代码示例中留下了相同的代码,它让我开始尝试弄清楚什么是错误的。 – TrueWill 2011-04-13 02:07:49