• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4315
  • Last Modified:

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'

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
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\\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.

  • 7
  • 6
  • 2
2 Solutions
slightwv (䄆 Netminder) Commented:
I believe the important message here is:  The provider is not compatible with the version of Oracle client

What version of Oracle client do you have installed?  It has to match the version of Oracle.DataAccess.dll you are using.


Can you not upgrade to the latest ODP.Net verions and maybe V2 or V4 of the driver?  1.x is a little old.
käµfm³d 👽Commented:
Whichever version of ODAC you installed (i.e. 32-bit vs. 64-bit) is what you need to set your platform target to (i.e. x86 vs. x64, respectively).
jxbmaSoftware ConsultantAuthor Commented:
Thanks for getting back to me with your comments.

I think it's important to note that my current installation (along with my outlined reference inclusions) works fine when I'm running my WinForm based application. I can connect to the DB, retrieve and insert data.

I am only seeing issues when I'm trying to move this functionality into a WCF service.


Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

slightwv (䄆 Netminder) Commented:
>>I've included this DLL in the references for my WCF service.

I assume it's a new project?  Make sure the referneces are exactly the same.

What it is compiled with, is what needs to be on the server that runs it.

ODP.Net is very picky about this.  The version numbers have to match exactly.  10g doesn't do it.  It has to match ALL version numbers.

I've done a lot with ODP.Net but am a Rookie when it comes to Visual Studio and all the .Net speak.  I realize that doesn't make sense but it is a long story...
jxbmaSoftware ConsultantAuthor Commented:
Additionally, I tried creating a client connection directly in my WPF application, using the same Oracle.DataAccess.dll as an include reference.

This worked fine.

So, somehow it appears that issue has to do with referencing this from either:
a) a WCF service
b) a WCF service that's being hosted through WcfSvcHost.exe

slightwv (䄆 Netminder) Commented:
Not being a .Net wizard:  I'm thinking it has to do with the GAC and what is registered with it.

The WCF service cannot locate the correct ODP.Net version (or possible any version).
jxbmaSoftware ConsultantAuthor Commented:
I do see the following in my VS2010 output window:


I verified that this is the correct version of the dll (same one that got loaded in my winform app and directly in my WPF app)

Not sure how to proceed this.
slightwv (䄆 Netminder) Commented:
The verion of that DLL now needs to match the version of the client it is finding.

I'm afraid you are quickly getting out of my .Net expertise if this is a VS config issue and I've not done anything with WCF.

So this might not be the right question but here goes:  When you debug/run the WCF project, does it run in the same enviornment as your WPF project?  I'm thinking they are finding different versions of the Oracle client that might be installed.
käµfm³d 👽Commented:
Wait! Why are you worried about a "First Chance Exception?" There isn't really anything you can do about such exceptions. Have you actually tried to run/call your WCF service? Is so, do you get a runtime exception?

jxbmaSoftware ConsultantAuthor Commented:

I'm not sure I follow you here.

Yes, I am running my WCF service from within VS2010.
It's hosted in WCFSvcHost.exe.
I'm getting the exception within my WCF service.
I call into an entry point from my WPF client.

This is an issue, because I can't connect to the Oracle DB.

The exception occurs on the following line:
             using (OracleConnection oraconn = new OracleConnection(dataConn))

If I add a reference to the Oracle.DataAccess.dll  directly to my client and add the
the above call. It works fine. I don't get the exception.

slightwv (䄆 Netminder) Commented:
I didn't see where you commented on kaufmed's post about Bit versions.

Confirm the bit versions of the WCF app and Oracle drivers.  Maybe force the compile from Any CPU to a specific bit version.

This seems to be a common theme to your same questions on the other Q&A sites (I count at least two other sites):  What you think it is trying to load isn't what is is actually loading.

Confirm you don't have local copies of Oracle.DataAccess.dll.
How many Oracle clients do you have installed?
Does Oracle.DataAccess.dll appear anywhere else on the system?
jxbmaSoftware ConsultantAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for jxbma's comment #a38318208

for the following reason:

Success. Success. Success.<br />Thanks for your help/comments/feedback.<br />I finally went with ODAC X64 11.2 and so far it seems to work fine.<br /><br />Thanks again,<br />JohnB
slightwv (䄆 Netminder) Commented:
I'm afraid I have to object.

Did I not say it appears to be a version issue and to upgrade to the latest drivers in http:#a38317500 ?

kaufmed suggested compatible Bit versions in http:#a38317502.

You never did clarify if you had multiple Oracle installs on the same machine.

My guess is the reason it appears 'fixed' is the last install set the environment for the last install.  If you install another version, you will likely be in the same situation.

This is important when you go to deploy.
jxbmaSoftware ConsultantAuthor Commented:
I did not have multiple versions of ORACLE  installs on my machine.
I had 10g installed (that's it).
(Remember the only thing this didn't work in was a WCF service. It worked fine directly in WinForm and WPF apps).
This had nothing to do with 32bit vs 64 bit versions.
I was already running th 64 bit version of ODAC 10.2.
This also had nothing to do with a "First Chance Exception" getting thrown.
It plain didn't work.

I actually got the answer verified in a Post on the Oracle website.
Essentially I was running a .Net 1X version of ODAC, which while it worked in the above 2 cases was not supported by Microsoft in the 4X environment.
I'm using the .Net 4X version of ODAC for 11.2 and things work fine in all cases.

I felt like your responses helped me get to where I could get the issue resolved.
That's why I awarded you the points.
If  you feel like that's an issue, I totally understand.

slightwv (䄆 Netminder) Commented:
I saw that post in the Oracle forums but I mentioned V1 was old in the first post and you should try V2 or V4.  I just missed the compatibility aspect.

>>That's why I awarded you the points.

You suggest closing with your own comment and not awarding the points.  That is what I objected to.  If I had a say, I would have split the points between the first two points.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now