Dylan Brams
Dylan Brams

Reputation: 2099

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

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.

Upvotes: 28

Views: 46393

Answers (10)

Thiago De Vargas
Thiago De Vargas

Reputation: 1

good afternoon

I want to share how I solved this same error:

  1. I started by starting visual studio 2019 cmd as administrator.

  2. I ran the following command line in cmd: gacutil -u Oracle.ManagedDataAccess

Basically this command line will remove the Oracle reference from the GAC (Global Assembly Cache), this way it will only get the reference from the package that is in the project (which nuget installs) and not from the oracle client.

Upvotes: 0

Stokely
Stokely

Reputation: 15809

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.

Upvotes: 3

Karl
Karl

Reputation: 415

If removing the DLL from the GAC is not an option, consider getting the next version of oracle.managedData.access 12.2.1 and just put them on the server in the bin directory. Afterwards you need to add an assemblyBinding to your web.config file.

This way you get arround pulling the 12.1.2 version from the GAC during runtime that will case the error. You do not need to recompile your app against the new version.

      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-12.1.2.0" newVersion="12.2.1.0" />
      </dependentAssembly>

Upvotes: 2

Carlos ABS
Carlos ABS

Reputation: 723

In my scenario, i have a console application consuming a class library database utility. I had to reference the Oracle.ManagedDataAccess also on the console application so it can find the dll on runtime. I don't know if this is the best approach, but worked for me.

Upvotes: 1

Toolkit
Toolkit

Reputation: 11119

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

Upvotes: 6

g.breeze
g.breeze

Reputation: 1978

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

Upvotes: 23

Jan Palas
Jan Palas

Reputation: 1895

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 

Upvotes: 29

Helius 06
Helius 06

Reputation: 87

There is definitely something weird with this issue. I was developing an app on my local server which ran fine but got this error when I uploaded the app to our server. The server has oracle client installed. After looking at this thread I copied the two DLLs (Oracle.ManagedDataAccess.dll & Oracle.ManagedDataAccess.EntityFramework.dll) from within oracle client and replaced the versions in my app bin directory. That fixed the issue.

Upvotes: 1

Greg Z.
Greg Z.

Reputation: 1566

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

Upvotes: 8

simon at rcl
simon at rcl

Reputation: 7344

You need to install the Oracle Client drivers. The .NET packages don't contain them; they provide a translation from the managed world to the unmanaged. The drivers are in the unmanaged world and need to be installed properly.

Upvotes: -1

Related Questions