ProxyFactoryFactory not configured

We recently upgraded our Windows C # projects from NHibernate 2.0 to 2.1. We updated our app.config to include "proxyfactory.factory_class" to point to the selected proxy ("NHibernate.ByteCode.Castle" in our case). After the update, the program builds and works as expected, without problems. Our problem is trying to open any forms that contain links to NHibernate when loading in the designer of Visual Studio 2008, now gives us the following error (as if we had not configured the proxy):

ProxyFactoryFactory has not been configured. initialize the "proxyfactory.factory_class" property of the factory session configuration 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 of 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> 

Does anyone know how to fix this problem? Thanks!

+4
source share
4 answers

I just developed the same error.

My data access assembly had the correct link to Nhibernate.ByteCode.Castle.Dll, and it appeared in the bin / release folder. Everything worked fine in the data access assembly.

The error was thrown when I tried to use the data access code from my test assembly. It turned out that although my test assembly referred to a data access project, it did not receive a copy of the Nhibernate.ByteCode.Castle.dll file. Adding a link to Nhibernate.ByteCode.Castle.dll in the test assembly solved the problem.

+3
source

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

This is a trick.

+1
source

It seems that the Designer is somehow initializing your SessionFactory. Have you tried adding dll ByteCodeProvider as a reference to your project?

[EDIT] Well ... the fact that the application launches upon deployment implies that everything is configured correctly. So your problem is VS DesignMode problem. Why (hell) are you using NHibernate in designmode? If you really need to, try installing ByteCodeProvider in your code. If you don't need it and you just need a fast desktop, you can check the current VS mode with this Hack, preventing Nhibernate from creating a 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 would try to find a control or something else that is needed for this static NHibernateHelper and try to separate.

0
source

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

0
source

All Articles