views:

9448

answers:

6

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();
        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 there is any other solution please help.

-- Regards

+3  A: 

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)

ShaneC
can you let me know the source from where i should get these dll's
Meetu Choudhary
They are in the NHibernate download.
ShaneC
To be more specific, the files are in Required_For_LazyLoading folder after you extract the NHibernate download.
kimsk
+7  A: 

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

Then your config line should work:

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

edit: Here's the relevant sections from my web config 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 config.

<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>
Ben
could you plese tell me what is the hibernate configuration and from where i will get the above dll's
Meetu Choudhary
Ben
I have downloaded it still the same problem
Meetu Choudhary
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)
Ben
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 refrence
Meetu Choudhary
If you want, send them to ben dot hyrman at gmail dot com
Ben
Thanks for your ID i have sent you the mail. i have attached the project as a zip file. please look into the matter
Meetu Choudhary
hey ben you haven't responded to my mail what happened?
Meetu Choudhary
Am looking at it now. Sorry, was out of town.
Ben
Sent you back an updated config that should work for youConfig 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.
Ben
Thanks for the update...
Meetu Choudhary
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?
Will Marcouiller
A: 

I have the same error and I did everything you said,by Still I get this error could you pleease help me ?:(

Tati
+1  A: 
<?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 dlls to the project reference

Sedot8
+1  A: 

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. 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 VS was not smart enough to figure out which DLLs were being lazy loaded?

Ogre Psalm33
A: 

rnate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle

Brian Gan