views:

1006

answers:

1

Considering this example as a base example. I created the application but when I execute this application 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

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(); //getting error at this line
        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();

    }
}
+2  A: 

Maybe you are missing to set the ProxyFactoryFactoryClass property before building you section factory.

Something like:

Config.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Linfu.ProxyProxyFactory, NHibernate.Bytecode.Linfu");

Don't forget to include the Linfu dll in your project.

EDIT: this happens due to an update to reference to Castle removed. You may obtain more information here: http://nhforge.org/blogs/nhibernate/archive/2008/11/09/nh2-1-0-bytecode-providers.aspx

nandokakimoto
where to add this line.. I am sorry if my question is too stupid but i am new to Nhibernate so please excue me and answer my doubt
Meetu Choudhary
I use it before creating my ISessionFactory, because my project was just a console app. However, you may use it in your web.config file. <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
nandokakimoto
i used it in my app.config but same error...
Meetu Choudhary
Did you add the LinFu corresponding dll in your project's references?
nandokakimoto
i have LinFu.DynamicProxy.dll instead of linfu.dll will it work if not then from where do i get this linfu.dll
Meetu Choudhary
Linfu.DynamicProxy.dll *is* the "LinFu corresponding dll", and it should be copied to your bin automagically if you reference the NHibernate.ByteCode.LinFu assembly.
Jørn Schou-Rode
There are a few typos in the second string given to Config.SetProperty in the original answer. It should read `NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.Bytecode.LinFu`
Jørn Schou-Rode