C# 未配置 ProxyFactoryFactory
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1209106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The ProxyFactoryFactory was not configured
提问by Jeremy Odle
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):
我们最近将我们的 windows 窗体 C# 项目从 NHibernate 2.0 升级到 2.1。我们更新了 app.config 以包含“proxyfactory.factory_class”以指向所选代理(在我们的例子中为“NHibernate.ByteCode.Castle”)。升级后,程序按预期构建并运行,没有任何问题。我们的问题是在 Visual Studio 2008 设计器中尝试打开任何在加载时引用 NHibernate 的表单时,现在给我们以下错误(好像我们没有配置代理):
The ProxyFactoryFactory was not configured. Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
未配置 ProxyFactoryFactory。使用可用的 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!
任何人都知道如何解决此问题的任何线索?谢谢!
回答by zoidbeck
It seems that the Designer somehow initializes your SessionFactory. Have you tried to add the ByteCodeProvider dll as a reference to your Project?
设计器似乎以某种方式初始化了您的 SessionFactory。您是否尝试将 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. 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:
[编辑] 好的...,应用程序在部署时运行的事实意味着一切都配置正确。所以你的问题是 VS DesignMode 问题。为什么(见鬼)你在设计模式中使用 NHibernate?如果您确实需要它,请尝试在您的代码中设置 ByteCodeProvider。如果您不需要它并且只想快速解决,您可以使用此 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 的东西,并尝试解耦。
回答by David P
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.
确保在 Nhibernate.ByteCode.Castle 引用的属性中,将其设置为“始终复制”,以便将其复制到 \bin 文件夹中。
回答by bsk
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.
我的数据访问程序集对 Nhibernate.ByteCode.Castle.Dll 有一个正确的引用,它出现在它的 bin/release 文件夹中。在数据访问程序集中一切正常。
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.
当我尝试使用我的测试程序集中的数据访问代码时抛出错误。结果表明,即使我的测试程序集引用了数据访问项目,它也没有获得 Nhibernate.ByteCode.Castle.dll 的副本。在测试程序集中添加对 Nhibernate.ByteCode.Castle.dll 的引用解决了该问题。
回答by Julian Birch
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.
这就是诀窍。