11

考慮本實施例中作爲鹼的例子,我創建的應用程序,但是當我執行此應用程序我得到下面的錯誤。的ProxyFactoryFactory沒有配置

的ProxyFactoryFactory沒有配置。使用可用的NHibernate.ByteCode提供程序之一初始化會話工廠配置部分的'proxyfactory.factory_class'屬性。例如:NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu例如:NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle

以下是我使用的代碼段。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using NHibernate; 
using NHibernate.Cfg; 

public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     Configuration cfg = new Configuration(); 
     cfg.AddAssembly("NHibernate"); 

     ISessionFactory factory = cfg.BuildSessionFactory(); 
     ISession session = factory.OpenSession(); 
     ITransaction transaction = session.BeginTransaction(); 
     User newUser = new User(); 
     newUser.Id = "joe_cool"; 
     newUser.UserName = "Joseph Cool"; 
     newUser.Password = "abc123"; 
     newUser.EmailAddress = "[email protected]"; 
     newUser.LastLogon = DateTime.Now; 

     // Tell NHibernate that this object should be saved 
     session.Save(newUser); 

     // commit all of the changes to the DB and close the ISession 
     transaction.Commit(); 
     session.Close();  
    } 
} 

我的app.config文件看起來像

<?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
     <configSections> 
     <section 
      name="nhibernate" 
      type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     /> 
     </configSections> 

     <nhibernate> 
     <add 
      key="hibernate.connection.provider" 
      value="NHibernate.Connection.DriverConnectionProvider" 
     /> 
     <add 
      key="hibernate.dialect" 
      value="NHibernate.Dialect.MsSql2000Dialect" 
     /> 
     <add 
      key="hibernate.connection.driver_class" 
      value="NHibernate.Driver.SqlClientDriver" 
     /> 
     <add 
      key="hibernate.connection.connection_string" 
      value="Server=localhost;initial catalog=nhibernate;Integrated Security=SSPI" 
     /> 
     <!--<add value="nhibernate.bytecode.castle.proxyfactoryfactory, nhibernate.bytecode.castle" key="proxyfactory.factory_class" />--> 
     <!--<property name="proxyfactory.factory_class">NHibernate.ByteCode.Linfu.ProxyFactoryFactory, NHibernate.ByteCode.Linfu</property>--> 
<!-- I have tried both the lines but still getting the same error --> 
     </nhibernate> 
    </configuration> 

LinFu.DynamicProxy.dll,而不是linfu.dll。它會起作用嗎?如果沒有,那麼我從哪裏得到這linfu.dll? 或者還有其他解決方案嗎?

+1

可能重複:http://stackoverflow.com/questions/956281/nhibernate-proxyexception和http://stackoverflow.com/questions/969894/error-using-nhibernate – 2009-06-10 14:07:47

+0

還有一個bug與建立目標http://blog.frozzn.com/2010/03/nhibernatebytecodecastleproxyfactoryfac.html – cgreeno 2010-03-20 02:10:57

回答

13

假設你有NHibernate的2.1 ALPHA3,複製從\Required_For_LazyLoading\LinFuLinFu.DynamicProxy.dllNHibernate.ByteCode.LinFu.dll到你的bin(或引用)

那麼你的配置行應該工作:

<add key="proxyfactory.factory_class" value="NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu" /> 

順便說一句,我更喜歡hibernate-configuration部分塊進行配置。

編輯:這是從我的web配置的相關章節,如果你想建立與hibernate-configuration代替鍵/值對。

此外,可以將hibernate-configuration零件放入其自己的文件hibernate.cfg.xml中。然後,您可以使用下載中的xsd nhibernate-configuration.xsd驗證您的配置。

<configSections> 
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/> 
</configSections> 
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
    <session-factory> 
     <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> 
     <property name="default_schema">kennelfinder.dbo</property> 
     <property name="connection.provider"> 
      NHibernate.Connection.DriverConnectionProvider 
     </property> 
     <property name="proxyfactory.factory_class"> 
      NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu 
     </property> 
     <property name="connection.connection_string">{Your connection string}</property> 
     <property name="show_sql">false</property> 
     <property name="connection.driver_class"> 
      NHibernate.Driver.SqlClientDriver 
     </property> 
     <property name="connection.isolation">ReadCommitted</property> 
     <property name="use_proxy_validator">true</property> 
     <mapping assembly="KennelFinder"/> 
    </session-factory> 
</hibernate-configuration> 
9

我們實際使用Castle Proxy並具有以下功能。

<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> 

之後,它只是一個確保所有在NHibernate的城堡延遲加載目錄中的文件是在bin的問題。

LinFu.DynamicProxy.dll是不夠的。您還需要NHibernate.ByteCode.Linfu.dll(可能還有其他人)。

+0

可以讓我從哪裏知道我應該得到的源這些dll的 – 2009-06-11 02:26:16

+0

他們在NHibernate的下載。 – 2009-06-11 14:41:50

1
<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
     <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/> 
    </configSections> 
    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
     <session-factory> 
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> 
      <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider </property> 
      <property name="proxyfactory.factory_class"> NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu </property> 
      <property name="connection.connection_string">Server=(local);database=HelloNHibernate;Integrated Security=SSPI;</property> 
      <property name="show_sql">false</property> 
      <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver </property> 
      <property name="connection.isolation">ReadCommitted</property> 
      <property name="use_proxy_validator">true</property> 
     </session-factory> 
    </hibernate-configuration> 
</configuration> 

複製LinFu.DynamicProxy.dllNHibernate.ByteCode.LinFu.dll到NHibernate的文件夾,並在同一個DLL文件添加到項目引用。

1

我通過Visual Studio 2008中的右鍵單擊「發佈...」功能發佈我的項目,努力推動我們的MVC/NHibernate的項目與我們的Web服務器時後得到這個錯誤。

原來,我只需要設置在發佈對話框中選擇正確的選項。特別是在「複製」部分中,指定「源項目文件夾中的所有文件」,然後開始工作。「只有運行此應用程序所需的文件」還不夠好,可能Visual Studio不夠聰明,無法確定哪些DLL正在被加載?

-2
rnate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> 
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>