2011-04-12 66 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