11

In diesem Beispiel als Basisbeispiel habe ich die Anwendung erstellt, aber wenn ich diese Anwendung ausführe, erhalte ich den folgenden Fehler.Die ProxyFactoryFactory wurde nicht konfiguriert

Die ProxyFactoryFactory wurde nicht konfiguriert. Initialisieren Sie die Eigenschaft 'proxyfactory.factory_class' des Konfigurationsabschnitts session-factory mit einem der verfügbaren NHibernate.ByteCode-Provider. Beispiel: NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu Beispiel: NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle

Im Folgenden ist der Code-Schnipsel ich verwende.

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();  
    } 
} 

Und meine app.config Datei sieht aus wie

<?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> 

ich LinFu.DynamicProxy.dll statt linfu.dll haben. Wird es funktionieren? Wenn nicht, woher bekomme ich dann linfu.dll? Oder gibt es eine andere Lösung?

+1

Mögliche Duplikate: http://stackoverflow.com/questions/956281/nhibernate-proxyexception und http://stackoverflow.com/questions/969894/error-using-nhibernate –

+0

Es gibt auch einen Fehler bei der build target http://blog.frozzn.com/2010/03/nhibernatebytecodecastleproxyfactoryfac.html – cgreeno

Antwort

13

Angenommen, Sie NHibernate 2.1 Alpha3 haben, kopieren LinFu.DynamicProxy.dll und NHibernate.ByteCode.LinFu.dll von \Required_For_LazyLoading\LinFu zu Ihrem bin (oder Referenzen)

Dann sollten Sie Ihre Konfigurationszeile funktionieren:

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

Als Nebenwirkung, ziehe ich die hibernate-configuration Abschnitt Block für die Konfiguration.

Bearbeiten: Hier sind die relevanten Abschnitte aus meiner Web-Konfiguration, wenn Sie mit hibernate-configuration anstelle von Schlüssel/Wert-Paaren einrichten wollte.

Es ist auch möglich, den hibernate-configuration Teil in eine eigene Datei namens hibernate.cfg.xml zu setzen. Sie können dann die xsd nhibernate-configuration.xsd im Download verwenden, um Ihre Konfiguration zu validieren.

<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> 
+0

können Sie mir sagen, was ist die Winterschlaf-Konfiguration und woher bekomme ich die oben genannten DLLs –

+1

Sie können NHibernate 2.1 Beta1 von http://sourceforge.net/project/downloading.php?group_id=73818&filename=NHibernate-2.1 herunterladen. 0.Beta1-bin.zip & a = 5370114 – Ben

+0

Ich habe es immer noch das gleiche Problem heruntergeladen –

9

Wir verwenden tatsächlich Castle Proxy und haben folgendes.

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

Danach ist es nur eine Frage, dafür zu sorgen, dass alle Dateien in dem NHibernate Castle verzögertes Laden Verzeichnis in dem Fach sind.

LinFu.DynamicProxy.dll ist nicht genug. Sie benötigen auch NHibernate.ByteCode.Linfu.dll (und möglicherweise andere).

+0

können Sie mir die Quelle von wo ich diese DLLs –

+0

bekommen Sie wissen lassen, dass sie im NHibernate Download sind. –

+2

Um genauer zu sein, befinden sich die Dateien im Ordner Required_For_LazyLoading, nachdem Sie den NHibernate-Download extrahiert haben. – kimsk

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> 

Copy LinFu.DynamicProxy.dll und NHibernate.ByteCode.LinFu.dll in den Ordner des NHibernate und die gleichen DLL-Dateien in das Projektverweis hinzuzufügen.

1

Ich habe diesen Fehler nach dem Veröffentlichen meines Projekts über Visual Studio 2008 mit der rechten Maustaste auf "Veröffentlichen ..." -Funktion, wenn Sie versuchen, unsere MVC/NHibernate-Projekt auf unseren Webserver schieben.

Es stellte sich heraus, dass ich nur die richtigen Optionen im Veröffentlichungsdialog festlegen musste. Insbesondere im Abschnitt "Kopieren", geben Sie "Alle Dateien im Quellprojektordner" an, und dann begann es zu arbeiten."Nur Dateien, die zum Ausführen dieser Anwendung benötigt werden" waren nicht gut genug, vielleicht war Visual Studio nicht schlau genug, um herauszufinden, welche DLLs lazy geladen wurden?

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

Kein Text. Unterbrochene Markup. Posted weg über die Antworten oben. Chapeau – SlapY

Verwandte Themen