Error using NHibernate
Asked Answered
I

1

2

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

    }
}
Imprimatur answered 9/6, 2009 at 12:53 Comment(3)
What does your config look like?Broddie
ok my config 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>Imprimatur
<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"/> </nhibernate> </configuration>Imprimatur
O
2

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

Otology answered 9/6, 2009 at 13:13 Comment(6)
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 doubtImprimatur
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>Otology
Did you add the LinFu corresponding dll in your project's references?Otology
i have LinFu.DynamicProxy.dll instead of linfu.dll will it work if not then from where do i get this linfu.dllImprimatur
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.Settee
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.LinFuSettee

© 2022 - 2024 — McMap. All rights reserved.