Oracle .Net ManagedDataAccess Error: Could not load type 'OracleInternal.Common.ConfigBaseClass' from assembly

40,399

Solution 1

There is a conflict between Oracle.ManagedDataAccess from NuGet and the one that is installed (by Oracle client installation) on a server and that is registered in GAC.

Unregister Oracle.ManagedDataAccess from GAC and you will get rid of the error: Run command line and navigate to the directory:

{Oracle home}\product\{version}\client_64\ODP.NET\managed\x64

There you should find OraProvCfg.exe file. Run the following command to unregister Oracle.ManagedDataAccess from GAC:

OraProvCfg /action:ungac /providerPath:Oracle.ManagedDataAccess 

Solution 2

You have to remove the Oracle.ManagedDataAccess assembly in your GAC (C:\Windows\Microsoft.NET\assembly...)

Use the command tool gacutil to remove the assembly:

C:\Program Files (x86)\Microsoft SDKs\Windows\YOUR_VERSION\bin\NETFX 4.6.1 Tools> gacutil /u Oracle.ManagedDataAccess

Solution 3

Was able to fix it by replacing references in the project to Oracle.ManagedDataAccess and Oracle.ManagedDataAccess.EntityFramework from those installed by the package manager to those installed by the oracle client installer. The versions are the same but the build number is different on those DLLs

Solution 4

As others said you need to remove Oracle.ManagedDataAccess from GAC.

I run {Oracle home}\product\12.1.0\dbhome_1\ODP.NET\managed\x64\unconfigure.bat and {Oracle home}\product\12.1.0\dbhome_1\ODP.NET\managed\x836\unconfigure.bat and it worked

Solution 5

We had the exact same problem as Dylan above. The issue appears to be with that specific Oracle version (4.121.2.0).

The solution was simple: Just go into Nuget and move up to the next version of your Nuget package for the Oracle.ManagedDataAccess.Client, 4.122.1.0.

Once we did that we could have mixed Oracle client or no-client environments or servers with or without the GAC Oracle installed, keep older apps that still use the GAC, and add new projects that use the Nuget packages. Its always a bad idea in these blogs to ask people to uninstall legacy stuff - like remove the Oracle dll in the GAC on a server - when you have environments with many legacy dependancies that still might reference it.

Share:
40,399
Dylan Brams
Author by

Dylan Brams

I make all sorts of things. Primarily glass, code, and databases. I tend to be extremely tenacious when I'm interested in something. I'm not sure I'm great at anything particular, but I once acquired an EE degree, I have been programming for around twenty five years, and I've been glassblowing for fifteen or so. Generally, I'm busy solving problems and answering questions.

Updated on July 25, 2022

Comments

  • Dylan Brams
    Dylan Brams almost 2 years

    I have a project that works locally, on our dev server, and on our production server.

    When I try to run it on the test server, I get the error below, and I don't know what to do about it beyond stare at my screen blankly. Hints? Process to trace the issue to its source?

    I've installed the NuGet package for Oracle 12.2, etc.

    Could not load type 'OracleInternal.Common.ConfigBaseClass' from assembly 'Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.TypeLoadException: Could not load type 'OracleInternal.Common.ConfigBaseClass' from assembly 'Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342'.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [TypeLoadException: Could not load type 'OracleInternal.Common.ConfigBaseClass' from assembly 'Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342'.]
    Oracle.ManagedDataAccess.EntityFramework.EntityFrameworkProviderSettings.Oracle.ManagedDataAccess.EntityFramework.EFProviderSettings.IEFProviderSettings.get_TracingEnabled() +0 Oracle.ManagedDataAccess.EntityFramework.EFProviderSettings.InitializeProviderSettings() +111 Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices..ctor() +629 Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices..cctor() +28

    [TypeInitializationException: The type initializer for 'Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices' threw an exception.]
    Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices.get_Instance() +24

    The Web.Config has the following blocks in it:

      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
      </configSections>
    

    AND

      <oracle.manageddataaccess.client>
        <version number="*">
          <dataSources>
            <dataSource alias="PVMDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=pdxcludds108.pacificorp.us)(PORT=11086))(CONNECT_DATA=(SERVICE_NAME=DDS1086.PACIFICORP.US))) " />
          </dataSources>
        </version>
      </oracle.manageddataaccess.client>
      <connectionStrings>
        <add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=USERID;Password=WORKINGPASSWORD;Data Source=PVMDataSource" />
        <add name="PVMEntities" connectionString="metadata=res://*/Models.PVMModel.csdl|res://*/Models.PVMModel.ssdl|res://*/Models.PVMModel.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string=&quot;DATA SOURCE=pdxcludds108.pacificorp.us:11086/DDS1086.PACIFICORP.US;PASSWORD=XXXXXXX;PERSIST SECURITY INFO=True;USER ID=XXX&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
    

    NOTE: There are other projects working on this server, they're just using a different version of the Oracle client for .Net. None of the others is using only the Managed driver. I am looking for a way to dig into this error, some hint as to where that type is sourced and loaded from.