The ProxyFactoryFactory was not configured
Asked Answered
I

5

11

Considering this example as a base example, I created the application but when I execute this application I am getting the following error.

The ProxyFactoryFactory was not configured. Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers. Example: NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu Example: NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle

The following is the code snippet I am using.

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

And my app.config file looks like

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

I have LinFu.DynamicProxy.dll instead of linfu.dll. Will it work? If not, then from where do I get this linfu.dll? Or is there any other solution?

Insincerity answered 10/6, 2009 at 6:28 Comment(2)
Probable duplicates: https://mcmap.net/q/1015166/-nhibernate-proxyexception and https://mcmap.net/q/1015167/-error-using-nhibernateLascar
There is also a bug with the build target blog.frozzn.com/2010/03/…Surely
H
13

Assuming you have NHibernate 2.1 Alpha3, copy LinFu.DynamicProxy.dll and NHibernate.ByteCode.LinFu.dll from \Required_For_LazyLoading\LinFu to your bin (or references)

Then your configuration line should work:

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

As an aside, I prefer the hibernate-configuration section block for configuration.

Edit: Here's the relevant sections from my web configuration if you wanted to set up with hibernate-configuration instead of key/value pairs.

Also, it's possible to just put the hibernate-configuration part in its own file called hibernate.cfg.xml. You can then use the xsd nhibernate-configuration.xsd that's in the download to validate your 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="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>
Hazem answered 11/6, 2009 at 0:12 Comment(10)
could you plese tell me what is the hibernate configuration and from where i will get the above dll'sInsincerity
You can download NHibernate 2.1 Beta1 from sourceforge.net/project/…Hazem
I have downloaded it still the same problemInsincerity
Did you copy all dlls from required_bins and the two dlls from Required_For_LazyLoading/LinFu? Did you copy them to your bin directory or add a reference to them so they're automatically copied? Are you still using the key/value approach? (I can try it that way to see if I get your error too)Hazem
yes i downloaded all the dlls and tried both the approches but still the same error i don't know how to uploadf the code files here. else if i have uploded my project for your refrenceInsincerity
Thanks for your ID i have sent you the mail. i have attached the project as a zip file. please look into the matterInsincerity
hey ben you haven't responded to my mail what happened?Insincerity
Am looking at it now. Sorry, was out of town.Hazem
Sent you back an updated config that should work for you Config in web.config not app.config. And, web site seems to work differently with hibernate.cfg.xml than Web App Project, so I removed that and just updated your web.config.Hazem
How can this be that I correctly created my config-file, copied all of the required DLLs, referenced the sharedLibs under the Reference Path section of my project properties and I still get the error about that ProxyFactoryFactory; only, and I mean ONLY when I don't specify Configure("./hibernate.cfg.xml").BuildSessionFactory(), since when I specify path to the config-file, it works fine?Guglielma
B
9

We actually use Castle Proxy and have the following.

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

After that it's just a matter of making sure that ALL of the files in the NHibernate Castle lazy loading directory are in the bin.

LinFu.DynamicProxy.dll isn't enough. You also need NHibernate.ByteCode.Linfu.dll (and potentially others).

Blader answered 10/6, 2009 at 19:56 Comment(3)
can you let me know the source from where i should get these dll'sInsincerity
They are in the NHibernate download.Blader
To be more specific, the files are in Required_For_LazyLoading folder after you extract the NHibernate download.Wildlife
M
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 and NHibernate.ByteCode.LinFu.dll to the NHibernate's folder and add the same DLL files to the project reference.

Myrtlemyrvyn answered 5/12, 2009 at 21:28 Comment(0)
S
1

I got this error after publishing my project via Visual Studio 2008's right-click "Publish..." feature, when trying to push our MVC/NHibernate project out to our web server.

It turned out I just needed to set the correct options in the publish dialog. In particular, in the "Copy" section, specify "All files in the source project folder", and then it started working. "Only files needed to run this application" was not good enough, perhaps Visual Studio was not smart enough to figure out which DLLs were being lazy loaded?

Sinfonia answered 9/12, 2009 at 14:5 Comment(0)
D
-2
rnate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
Devil answered 17/12, 2009 at 21:31 Comment(1)
No text. Broken Markup. Posted way beyond the answers above. ChapeauMoscow

© 2022 - 2024 — McMap. All rights reserved.