Reputation: 4359
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
.
I'm running on a windows 7 (64 bit machine).
I'm using VS 2010.
I'm using Oracle 10g on the backend.
I'm the Oracle.DataAccess.dll (ODP.Net) from the following installed instance
c:\oracle\product\10.2.0\.....\ODP.NET\bin\1.x\Oracle.DataAccess.dll
I've included this DLL in the references for my WCF service.
I've included this service as a project within my VS WPF solution.
The service starts up automatically when I start my WPF application in VS 2010.
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}
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
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:
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