JohnB
JohnB

Reputation: 4359

Why am I getting a 'System.TypeInitializationException' when I create an Oracle connection in my .Net WCF web service?

I'm currently working on implementing a WCF service which talks to an Oracle 10g database on the backend. When I attempt to connect to the database from within my service, I get the following exception: System.TypeInitializationException.

At runtime I see the following output in my debug output window:

'WcfSvcHost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC\Oracle.DataAccess\1.102.2.20__89b483f429c47342\Oracle.DataAccess.dll' A first chance exception of type 'System.TypeInitializationException' occurred in Oracle.DataAccess.dll

Sure enough, I look at the exception details in the debugger and I see the following information (this occurs when I attempt to create a new ORACLE connection):

"The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception." InnerException {"The provider is not compatible with the version of Oracle client"} System.Exception {Oracle.DataAccess.Client.OracleException}

A Little Background:

I'm basically migrating my data layer to a WCF service. The same service layer previously existed in a WinForm application. Everything works fine in my WinForm application. I include the same reference to the Oracle.DataAccess.dll and all my reads/writes with the database work fine.

Is there something obviously different between the WCF and WinForm access/use of the DLL? Is there some limitation I'm unaware of? Is there an issue running this through VS2010 in the debugger?

I have absolutely no idea what is going on here. Any hints/direction would be greatly appreciated.

Upvotes: 0

Views: 6106

Answers (1)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174319

No, there is nothing special on the .NET side you need to be aware of.
Some of the reasons for this specific error are:

  1. Your application targets .NET 4 but you only have ODP.NET for .NET 2 or even .NET 1 installed
  2. You are making use of a local Oracle Instant client and are missing some of the unmanaged DLLs.

Actually, your exception message states that it tried to load the Oracle.DataAccess.dll from the GAC with the version number 1.102.2.20. This seems to be the .NET 1 version of ODP.NET as the version for .NET 2 has the number 2.102.2.20 and for .NET 4 it has the number 4.102.2.20.

Maybe your Winforms application had a version of Oracle.DataAccess.dll in its bin folder and was using that instead the one in the GAC?


These problems are the reason why I switched to a local Oracle Instant client in my projects. This adds 130 MB to my deployment but it doesn't matter as it's all corporate software.

Upvotes: 1

Related Questions