The ProxyFactoryFactory was not configured

10.4k Views Asked by At

We have recently upgraded our windows forms C# project from NHibernate 2.0 to 2.1. We updated our app.config to include the "proxyfactory.factory_class" to point to the chosen proxy ("NHibernate.ByteCode.Castle" in our case). After the upgrade the program builds and runs as expected, with no issues. Our problem is when attempting to open any forms that have references to NHibernate upon load within the Visual Studio 2008 designer, now give us the following error (as if we hadn't configured the proxy):

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

Stack trace:

   at NHibernate.Bytecode.AbstractBytecodeProvider.get_ProxyFactoryFactory()
   at NHibernate.Cfg.Configuration.Validate()
   at NHibernate.Cfg.Configuration.BuildSessionFactory()
   at DAL.NHibernateHelper..cctor() in ...\DAL\NHibernateHelper.cs:line 62

Line 62 from NHibernateHelper:

    static NHibernateHelper()
    {
        var cfg = new Configuration();
        cfg.Configure();
        cfg.AddAssembly("DAL");
        sessionFactory = cfg.BuildSessionFactory(); // <-- line 62
    }

Here is our app.config configuration for NHibernate:

<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="connection.connection_string">Server=ourserver;initial catalog=ourdb;Integrated Security=SSPI</property>
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
      <property name="show_sql">true</property>
    </session-factory>
  </hibernate-configuration>
</configuration>

Anyone have any clues on how to remedy this issue? Thanks!

4

There are 4 best solutions below

1
On

I had the same problem. To fix it, I had to not only explicitly reference the DLL, but add a method to the test DLL that explicitly created NHibernate.ByteCode.Castle.ProxyFactoryFactory.

That did the trick.

3
On

I just worked out the same error.

My data access assembly had a proper reference to Nhibernate.ByteCode.Castle.Dll and it appeared in its bin/release folder. Everything worked fine within the data access assembly.

The error was thrown when I tried to use data access code from my test assembly. It turned out that even though my test assembly referenced the data access project, it did not get a copy of the Nhibernate.ByteCode.Castle.dll. Adding a reference to Nhibernate.ByteCode.Castle.dll in the test assembly solved the problem.

3
On

It seems that the Designer somehow initializes your SessionFactory. Have you tried to add the ByteCodeProvider dll as a reference to your Project?

[EDIT] Ok..., the fact that the Application runs when deployed implies that everything is configured correctly. So your problem is a VS DesignMode problem. Why (the heck) are you using NHibernate in designmode? If you really need it try setting the ByteCodeProvider in your code. If you don't need it and just want a quick workarround you could check the current VS mode with this Hack preventing Nhibernate from building the SessionFactory:

static NHibernateHelper()
{
    if(System.Diagnostics.Process.GetCurrentProcess().ProcessName != "devenv")
    {
        var cfg = new Configuration();
        cfg.Configure();
        cfg.AddAssembly("DAL");
        sessionFactory = cfg.BuildSessionFactory(); // <-- line 62
    }
}

If i were you i'd try to find the control or whatever needs this static NHibernateHelper and try to decouple.

1
On

Make sure that in the properties of your Nhibernate.ByteCode.Castle reference, you set it to "Copy Always" so that it gets copied to your \bin folder.