C# 无法从NHibernate.driver.OracleDataClientDriver创建驱动程序
下面是引发异常的代码:C# 无法从NHibernate.driver.OracleDataClientDriver创建驱动程序,c#,oracle,nhibernate,connection,driver,C#,Oracle,Nhibernate,Connection,Driver,下面是引发异常的代码: public static class NHibernateSessionManager { private static ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory(); public static ISession GetSession(string clientId) { if (ContextSes
public static class NHibernateSessionManager
{
private static ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
public static ISession GetSession(string clientId)
{
if (ContextSession == null)
ContextSession = sessionFactory.OpenSession(new OracleIntercerptor(clientId.ToUpper()));
else
((OracleConnection)ContextSession.Connection).ClientId = clientId;
return ContextSession;
}
// - snip -
}
以及对引发异常的代码的调用:
private ISession NHibernateSession
{
get
{
return NHibernateSessionManager.GetSession(SessionWrapper.GetUser());
}
}
我得到一个TypeInitializationException
{”的类型初始值设定项
'Sigaf.prespuesto.EntidadesDAL.NHibernate.NHibernate事务经理'
引发了异常。“}
除了
{”无法从中创建驱动程序
NHibernate.Driver.OracleDataClientDriver。“}
还有一些内在的例外情况导致了NRE:
对象引用未设置为
对象的实例。在 NHibernate.Driver.OracleDataClientDriver..ctor() NHibernate v3.0 目标框架v4.0 此代码实现适用于其他类似的解决方案 哦,Hibernate.config文件:
<?xml version="1.0"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="current_session_context_class">web</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
<property name="connection.connection_string_name">Sigaf</property>
<property name="default_schema">PRE</property>
<property name="show_sql">true</property>
<mapping assembly="Sigaf.Presupuesto.EntidadesDAL" />
</session-factory>
</hibernate-configuration>
NHibernate.Connection.DriverConnectionProvider
NHibernate.方言
网状物
NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu
NHibernate.Driver.OracleDataClientDriver
西格夫
之前
真的
确保实际的Oracle驱动程序位于应用程序bin文件夹中
例如,在Visual Studio中,您应该在项目中添加对Oracle.DataAccess.dll的引用
选择DLL=>右键单击它=>在属性网格中选择Copy Local=True
这应该可以解决您的问题。我在数据访问项目中这样做了,但没有成功。一旦我在我的应用程序项目(MVC3)中这样做了,它就工作了。这是有道理的,一个项目只会引入引用需要编译的程序集。对于这些类型的引用(仅为反射/配置引用),它们必须位于宿主项目中。