gpt4 book ai didi

asp.net - ProxyFactoryFactory 未配置

转载 作者:行者123 更新时间:2023-12-02 07:07:10 27 4
gpt4 key购买 nike

考虑到此示例作为基本示例,我创建了该应用程序,但当我执行此应用程序时,出现以下错误。

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

以下是我正在使用的代码片段。

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 = "joe@cool.com";
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();
}
}

我的 app.config 文件看起来像

    <?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>

我有 LinFu.DynamicProxy.dll 而不是 linfu.dll。它会起作用吗?如果没有,那么我从哪里获取这个linfu.dll?或者还有其他解决办法吗?

最佳答案

假设您有 NHibernate 2.1 Alpha3,请从 \Required_For_LazyLoading\LinFu 复制 LinFu.DynamicProxy.dllNHibernate.ByteCode.LinFu.dll到您的垃圾箱(或引用文献)

那么你的配置行应该可以工作:

<add key="proxyfactory.factory_class" value="NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu" />

顺便说一句,我更喜欢使用 hibernate-configuration 部分块进行配置。

编辑:如果您想使用 hibernate-configuration 而不是键/值对进行设置,这里是我的 Web 配置中的相关部分。

此外,还可以将 hibernate-configuration 部分放入其自己的名为 hibernate.cfg.xml 的文件中。然后,您可以使用下载中的 xsd nhibernate-configuration.xsd 来验证您的配置。

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

关于asp.net - ProxyFactoryFactory 未配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/973979/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com