Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempt to load Oracle client libraries threw BadImageFormatException

Tags:

.net

oracle

wpf

While trying to connect to oracle database from .net getting the following exception:

Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.

After going through many links i tried to overcome this exception by changing the platform target to Any CPU.Since it is wpf application,after changing the platform target it is throwing the following exception:

'The invocation of the constructor on type 'SSC_GIP_UI.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.

But it runs fine with platform target x86 without throwing the above exception ,but it throws BadImageFormatException.

The enironment on which i am working is: Windows server 2008,
.net framework 4.0, oracle 11g (64-bit)

can anyone tell me.how to fix it?

like image 231
Liza Avatar asked Mar 19 '13 11:03

Liza


3 Answers

This error indicates that you have a mismatch between 32 bits and 64 bits components in your application.

When you run an application in 64 bits Windows, it may run as either 64 bits or 32 bits. If you have set the platform target as x86, it will run as 32 bits. If you have set your platform target as x64 or AnyCpu it will run as 64 bits.

Oracle has different versions of it's client, one is 32 bits and the other is 64 bits. So, if your application is running in 32 bits mode, you need to make sure your 32 bits Oracle client is installed.

like image 117
GTG Avatar answered Nov 06 '22 03:11

GTG


I think maybe you have to: Open IIS, find what application pool this application uses Go to that application pool, set a mark in 'Enable 32-bit applications'

like image 29
Njal Avatar answered Nov 06 '22 02:11

Njal


A completely alternative solution would be to use the Oracle Data Provider for .NET which will give you access to the Oracle.ManagedDataAccess dll that works regardless of whether you're on 32 or 64 bits. Read this article from Oracle Magazine for a gentle introduction.

You can use it pretty much the same way as the System.Data.OracleClient although I'm not sure if there's feature parity between the two, so your mileage may vary.

like image 20
Ruben Steins Avatar answered Nov 06 '22 01:11

Ruben Steins