Oracle – Fluent NHibernate – Configure Oracle Data Provider ODP

configurationfluent-nhibernateodp.netoracle

I am brand new to NHibernate and Fluent NHibernate and I am trying to get the following confguration to work.

private static ISessionFactory CreateSessionFactory()
{
     return Fluently.Configure() 
       .Database(
       OracleDataClientConfiguration.Oracle10.ConnectionString("Data Source=mysource;User ID=myid;Password=mypwd;")                  
          )
         .Mappings(m =>
            m.FluentMappings.AddFromAssemblyOf<Program>())
         .BuildSessionFactory();

    }

I have the Oracle.DataAccess assembly referenced. I am using VS 2010 and .Net 4

I get the following exception :

FluentNHibernate.Cfg.FluentConfigurationException was unhandled
Message=An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

Source=FluentNHibernate
StackTrace:
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 98
at HibernateLearning.Program.CreateSessionFactory() in C:\Projects\CPS Test Concepts\Main\Source\CPSTestConcepts\Source\HibernateLearning\Program.cs:line 48
at HibernateLearning.Program.Main(String[] args) in C:\Projects\CPS Test Concepts\Main\Source\CPSTestConcepts\Source\HibernateLearning\Program.cs:line 21
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: NHibernate.HibernateException
Message=Could not create the driver from NHibernate.Driver.OracleDataClientDriver, NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
Source=NHibernate
StackTrace:
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary2 settings)
at NHibernate.Connection.ConnectionProvider.Configure(IDictionary
2 settings)
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary2 settings)
at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary
2 properties)
at NHibernate.Cfg.Configuration.BuildSettings()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 93
InnerException: System.Reflection.TargetInvocationException
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type)
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
InnerException: NHibernate.HibernateException
Message=The IDbCommand and IDbConnection implementation in the assembly Oracle.DataAccess could not be found. Ensure that the assembly Oracle.DataAccess is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use element in the application configuration file to specify the full name of the assembly.
Source=NHibernate
StackTrace:
at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
at NHibernate.Driver.OracleDataClientDriver..ctor()
InnerException:

Best Solution

I figured it out. When you reference the ODP you have to set the the copy local property of the reference to true otherwise it won't find the objects it is looking for.

One hurdle down, I'm sure there will be more but I am loving these tools!

Paul

Related Question