简体   繁体   English

未配置ProxyFactoryFactory

[英]The ProxyFactoryFactory was not configured

We have recently upgraded our windows forms C# project from NHibernate 2.0 to 2.1. 我们最近将我们的Windows窗体C#项目从NHibernate 2.0升级到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). 我们更新了app.config以包含“proxyfactory.factory_class”以指向所选代理(在我们的例子中为“NHibernate.ByteCode.Castle”)。 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): 我们的问题是在Visual Studio 2008设计器中加载时尝试打开任何引用了NHibernate的表单时,现在给出了以下错误(好像我们没有配置代理):

The ProxyFactoryFactory was not configured. 未配置ProxyFactoryFactory。 Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers. 使用一个可用的NHibernate.ByteCode提供程序初始化session-factory配置节的'proxyfactory.factory_class'属性。

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: 来自NHibernateHelper的第62行:

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

Here is our app.config configuration for NHibernate: 这是我们对NHibernate的app.config配置:

<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! 谢谢!

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. 我的数据访问程序集有一个适当的引用Nhibernate.ByteCode.Castle.Dll,它出现在它的bin / release文件夹中。 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. 事实证明,即使我的测试程序集引用了数据访问项目,它也没有获得Nhibernate.ByteCode.Castle.dll的副本。 Adding a reference to Nhibernate.ByteCode.Castle.dll in the test assembly solved the problem. 在测试程序集中添加对Nhibernate.ByteCode.Castle.dll的引用解决了这个问题。

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. 要修复它,我不仅要显式引用DLL,还要为显式创建NHibernate.ByteCode.Castle.ProxyFactoryFactory的测试DLL添加一个方法。

That did the trick. 这就是诀窍。

It seems that the Designer somehow initializes your SessionFactory. 似乎Designer以某种方式初始化了SessionFactory。 Have you tried to add the ByteCodeProvider dll as a reference to your Project? 您是否尝试将ByteCodeProvider dll添加为项目的引用?

[EDIT] Ok..., the fact that the Application runs when deployed implies that everything is configured correctly. [编辑]好的......,部署应用程序时运行的事实意味着所有内容都已正确配置。 So your problem is a VS DesignMode problem. 所以你的问题是VS DesignMode问题。 Why (the heck) are you using NHibernate in designmode? 为什么(哎呀)你在设计模式中使用NHibernate? If you really need it try setting the ByteCodeProvider in your code. 如果你真的需要它,请尝试在代码中设置ByteCodeProvider。 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: 如果您不需要它并且只是想快速处理,您可以使用此Hack检查当前的VS模式,防止Nhibernate构建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. 如果我是你,我会尝试找到控件或任何需要这个静态NHibernateHelper并试图解耦。

确保在Nhibernate.ByteCode.Castle引用的属性中,将其设置为“始终复制”,以便将其复制到\\ bin文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM