dawriter
dawriter

Reputation: 435

Oracle ODP.NET error

I have a VS 2012 Web Project Up. I have ODP.NET installed as we are an Oracle Workshop. I inherited a project that uses Oracle.ManagedAccess.Data and EF.

Upon running the project in VS 2012, I get the following error:

There is a duplicate 'oracle.manageddataaccess.client' section defined..

The solution was to disable the following line in web.config

<!--<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />-->

Which was fine. The project compiled but upon executing a simple command such as getting a password back where it has to read the database another error was tripped up:

System.Data.ConstraintException: Column 'InvariantName' is constrained to be unique.  Value 'Oracle.ManagedDataAccess.Client' is already present.

Now I'm aware that the error is tripped up by ODP.NET and having it exist in the GAC thus the double error reporting.

Is there another line I should be commenting out or is there a way to disable ODP.NET briefly? I don't want to install that client as I use it for other projects.

thanks

Upvotes: 14

Views: 25202

Answers (4)

laughsloudly
laughsloudly

Reputation: 614

There are multiple ways to solve this problem. Not everyone has the luxury or desire to modify the machine.config (especially on a server). Perhaps the easiest way to solve this problem is to use bindingRedirect in your web.config (or app.config, if not a web application).

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly>
      <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-4.122.21.1" newVersion="4.122.21.1"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

NOTE: The version I am using is 4.122.21.1. Be sure you match your own version that you are using.

NOTE: The redirect is on Oracle.ManagedDataAccess, not Oracle.ManagedDataAccess.Client; this is a common mistake that developers make.

If you want to make the change in the machine.config, proceed carefully as this could have unanticipated consequences on other apps on the machine. The simplest modification is to change the version of the Oracle.ManagedDataAccess.Client section from a strong version to any version by using an asterisk "*".

<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=*, Culture=neutral, PublicKeyToken=89b483f429c47342" />

If you need additional clarification, let me know and I can give more details.

Upvotes: 0

Mohammad Yasir Arafat
Mohammad Yasir Arafat

Reputation: 705

I was getting the same error for an ASP.Net MVC project. I found that there is a version mismatch for oracle.manageddataaccess.client in the Web.config of the project, and machine.config in

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config, and 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config. 

I had Version=4.122.18.3 in the Web.config and Version=4.122.1.0 in the machine.config.

I updated the version(replaced Version=4.122.1.0 of oracle.manageddataaccess.client with 4.122.18.3) in both the machine.config, and the problem resolved.

Upvotes: 19

Ryno Potgieter
Ryno Potgieter

Reputation: 9

In my case I have multiple projects. One a Entity Framework data model, another which is an WCF Service using the EF Model, a WPF project using the WCF Service, and finally, my ASP.NET MVC prject, using the Entity Framework Data model directly. We use Oracle and had a Nuget package oracle.manageddata. I used Version 12.1.21 in all the others, except my ASP project (which had version 12.1.22). After downgrading to what the other projects are using, my Web ASP is running again. Using different Nuget versions in various projects, in the same solution, doesn't seem to be such a good idea.

Upvotes: 0

Alex R.
Alex R.

Reputation: 684

I found the following on the Oracle site regarding the "There is a duplicate 'oracle.manageddataaccess.client' section defined.":

If your application is a web application and the above entry was added to a web.config and the same config section handler for "oracle.manageddataaccess.client" also exists in machine.config but the "Version" attribute values are different, an error message of "There is a duplicate 'oracle.manageddataaccess.client' section defined." may be observed at runtime. If so, the config section handler entry in the machine.config for "oracle.manageddataaccess.client" has to be removed from the machine.config for the web application to not encounter this error. But given that there may be other applications on the machine that depended on this entry in the machine.config, this config section handler entry may need to be moved to all of the application's .NET config file on that machine that depend on it.

I hope it helps.

Upvotes: 24

Related Questions