<DbProviderFactories> causing System.TypeInitializationException - can I choose whether to call it or not?

Topics: Data Access Application Block, Enterprise Library Core
Nov 4, 2014 at 11:29 AM
Edited Nov 4, 2014 at 11:30 AM

I had a problem with ODP.Net causing Exceptions in the statement "EnterpriseLibrary...GetInstance<Database>(any value)" on a 64bit PC.

The solution was to add a DBProvideFactories entry below to my APP.CONFIG. However, the same code has to run on a 32bit desktop which does not have ODP.NET and when I run the code, I get a "System.TypeInitializationException". Is there a way I can choose whether to run the <DBProviderFactories> elements e.g. IF statements in APP.CONFIG or put the whole thing in code?
      <remove invariant="Oracle.ManagedDataAccess.Client" />
      <add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client"
description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
Nov 4, 2014 at 1:36 PM
I'm not sure what type of application you have. However, one option is to use a different configuration file based on the build configuration. SlowCheetah looks like it could help for doing this with app.config. This would result in different deployment packages for x86 and x64. It also might be an option to select the proper configuration at install time depending on type of application (e.g. custom installer).

If you want to have one package then you can also add DbProviderFactory programmatically. See: Add a DbProviderFactory without an App.Config.

Randy Levy
Enterprise Library support engineer
Support How-to
Marked as answer by smallmj on 11/10/2014 at 12:25 PM