app.config not working when adding DbProviderFactories entry for ODP.NET

985 Views Asked by At

I try to use Oracle.ManagedDataAccess.Client in my application. I added this to my app.config (embedded resource):

<system.data>
    <DbProviderFactories>
        <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=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </DbProviderFactories>
</system.data>

The DBFactories list does not contain Oracle.ManagedDataAccess.Client. When I add the same entry to my maschine.config (C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config) it all works fine.

<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=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>

That's the way I query the DBProviders (but the providers list does not contain my entry anyway):

DataTable Providers = DbProviderFactories.GetFactoryClasses();
Providers.Select("InvariantName = 'Oracle.ManagedDataAccess.Client'");

So why isn't my application configuration used? I want to deploy my application to clients. I am not sure if I can change their maschine.config.

Thanks for your help

UPDATE: I finally found a possible explanation: when I embedded the config (I like to do that when there is no reason the place the config file beside the exe) it does not work. But when I change the config-type to "nothing" and place them beside the exe it all works fine.

1

There are 1 best solutions below

0
On

With this configuration it finally worked:

<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
  </startup>
  <system.data>
    <DbProviderFactories>
      <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=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <publisherPolicy apply="no"/>
        <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
        <bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>