16

Here's the code raising the exception:

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

and the call to the code where the exception is raised:

    private ISession NHibernateSession
    {
        get 
        {
            return NHibernateSessionManager.GetSession(SessionWrapper.GetUser());
        }
    }

I get a TypeInitializationException

{"The type initializer for 'Sigaf.Presupuesto.EntidadesDAL.NHibernate.NHibernateSessionManager' threw an exception."}

With an inner exception of

{"Could not create the driver from NHibernate.Driver.OracleDataClientDriver."}

A few more inner exceptions lead me to a NRE:

Object reference not set to an instance of an object.
at NHibernate.Driver.OracleDataClientDriver..ctor()

NHibernate v3.0 Target Framework v4.0 This code implementation is working for other, similar, solutions.

Oh, the Hibernate.config file:

<?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>
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
bevacqua
  • 47,502
  • 56
  • 171
  • 285

1 Answers1

37

Make sure the actual Oracle driver is in your application bin folder.

In Visual Studio you should add a reference to Oracle.DataAcess.dll in your project for example.

Select the DLL => Right click it => In the Properties grid select Copy Local = True.

This should solve your problem.

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
  • 4
    I did this in my data access project but it didn't work. Once I did this in my application project (MVC3) it worked. – Alex Feb 16 '12 at 18:31
  • 4
    That makes sense, a project will only bring in assemblies that a reference requires to compile. For these type of references, which are reflection/configuration-only references, they must be in the host project. – Rich Apr 05 '12 at 14:13