Click here to Skip to main content
15,886,101 members
Please Sign up or sign in to vote.
4.00/5 (4 votes)
I am getting a "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."

I have a main ASP.NET project which is 64 bit(set to Auto though) and another oracle database project 64 bit(set to Auto). I am getting the above error in "Connection.open()' in the oracle database project. I am using System.Data.Oracle client, the 64 bit version-2.0.50727.5420


Edit.I thought I would mention that I am using the latest Instant Client v 11.0.2.0 from the Oracle to run my program.
....I also tried the ODAC provider from Oracle. Same problem.

Also the oracle database project seems to run fine in x64 bit mode by itself without any problems. The way i verified that it was running in 64 bit mode was I just looked into task manager while the Oracle database project was executing and there was no *32 in the name of the project. All the frame references to this project are already 64 bit. It seems like the issue is the ASP.NET project which is at 3.5

Meanwhile below are things i did to try resolve the issue . It did start working randomly at some point but then something happened and it is not working anymore. I thought I fixed it but i cannot be sure if I did.->


1. Removed all 64 bit references from my projects. Added 64 bit dll references from Windows\Microsoft.Net\2.0*\.NETFRAMEWORK64.

2. Added 32 bit enabled support in my Application pool in IIS7.

3. When i run the project, I still get the& '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


Has anybody had any success with this?

Anybody have suggestions. I could make my whole project x86 but then I am using a 64 bit server processor..so it seems bad. Should I download Orcale Data access provider from Oracle and try it? Its supposed to be 64 bit.

Any suggestions will be much appreciated.

Thanks
Jobin Thomas
Posted
Updated 24-Mar-18 17:44pm
v3

Normally, you don't have to explicitly set the platform for a Microsoft .Net program. You specify AnyCPU in Visual Studio and your program gets compiled to IL code. At runtime Microsoft.Net compiles just in time the IL code into x86 or x64 depending on the OS.

By explicitly specifying the platform in Visual Studio you force that during runtime the IL code will be transformed into x86 or x64.

It becomes different when you reference an unmanaged library, which is the case in your application. You can´t reference a 64 bits unmanaged dll from a 32 bits program and vice versa. The only option is to explicitly specify the platform in Visual Studio.

I don´t think this is a direct solution to your problem but it may give you some idea about why this is happening and give you some pointers on how to solve this.
 
Share this answer
 
Comments
[no name] 19-Mar-11 10:25am    
Thats the confusing part. I am not referencing any unmanaged libraries in my program. I have 64 bit versions of all the .net frameworks as references. System.Data.OracleClient is a part of managed .NET.
Why am I still getting the Bad Image exception?
IIS 32 bit enabled and 32 bit Oracle client works.
IIS 32 bit disabled and 64 bit Oracle client works too.
Nothing strange really, it's just a PITA to debug.
More fun when you realize that Visual Studio is a 32 bit program that won't work with 64bit client.
 
Share this answer
 
Comments
[no name] 13-Jun-11 19:52pm    
Should be.

IIS 32 bit enable and 64 bit Oracle client works too and 32 bit Application works too. 32 bit Application is not working.
FOR DESKTOP MODULE

SET SOLUTION PROPERTY ADVANCE COMPILE OPTION TARGET CPU TO X86 IT WILL SOLVE THE CONNECTIVITY ISSUE

WHILE IN WEB

CREATE ONE DIFFERENT APPLICATION POOL IN IIS ASSIGN NAME TO IT SET ENABLE 32 BIT APPLICATION POOL=TRUE.
AND ASSIGN THAT APPLICATION POOL TO PARTICULAR WEB MODULE IN IIS IT WILL WORK F9....



Kunal shah

Kunal.shah06@gmail.com
 
Share this answer
 
v2
Comments
Reena Kshatriya 31-Jul-12 11:02am    
This worked for me
KK shah 23-Nov-12 3:20am    
humm its generally works in all situation
KK shah 2-Oct-13 1:39am    
Yes it did works in all solution
WOW...Solved this issue finally!!!!

I guess I got confused by all the posts I was reading that told me to set the 32 bit Enabled =true in the Application pool for IIS.

The solution seems to be to set 32 Bit Enabled=false in IIS because for some reason setting 32 bit Enabled =true seems to make IIS execute the code as 32 bit which cause the exception.

This is the post that helped me solve this issue..Thanks to the provider..

http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/b8cb5f3d-8e61-4e63-b325-d07b261f77ac/[^]

So just goto your application pool and disable 32 bit Enabled. Easy!!!

Thanks for looking at my posts.
 
Share this answer
 
v2
Comments
kguyot 8-Mar-12 8:23am    
This worked for me as well. The error message was a little miss leading, but This solved it for me! Great work!
StefanHam 10-Jul-12 6:23am    
Worked great for me to, thanx allot
I might have found out why i am having this problem. I was checking all the modules loaded in my ASP.NET project and I see that all the references are to the 32 bit dll's instead of the 64 bit dlls( The modules can be checked by going into Debug-> Windows->Modules . Below is a few of the post what I see->



C:\Windows\assembly\GAC_32\System.Transactions\2.0.0.0__b77a5c561934e089\System.Transactions.dll Yes N/A Symbols loaded. C:\Users\ctdi\AppData\Local\Temp\SymbolCache\MicrosoftPublicSymbols\System.Transactions.pdb\BD0888386832412091CB17B3C28CF7721\System.Transactions.pdb 18 2.0.50727.4927 (NetFXspW7.050727-4900) 6/4/2009 1:41 AM 659C0000-65A5C000 [5868] w3wp.exe: Managed
System.EnterpriseServices.dll

C:\Windows\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll Yes N/A Cannot find or open the PDB file. 19 2.0.50727.5420 (Win7SP1.050727-5400) 9/29/2010 12:02 AM 1C700000-1C79D000 [5868] w3wp.exe: Managed

C:\Windows\assembly\GAC_32\System.Data.OracleClient\2.0.0.0__b77a5c561934e089\System.Data.OracleClient.dll Yes N/A Cannot find or open the PDB file. 21 2.0.50727.5420 (Win7SP1.050727-5400) 9/29/2010 12:04 AM 626E0000-627F4000 [5868] w3wp.exe: Managed</pre>

All of these seem to be referencing the 32 bit libraries instead of the 64 bit library. I checked my standalone Oracle Client project. Below is what i see.

<pre lang="msil">mscorlib.dll C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll Yes N/A Cannot find or open the PDB file. 1 2.0.50727.5420 (Win7SP1.050727-5400) 9/28/2010 11:53 PM 000007FEF8250000-000007FEF912C000 [6264] DAccess_OLP.vshost.exe: Managed

System.Data.dll C:\Windows\assembly\GAC_64\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll Yes N/A Cannot find or open the PDB file. 10 2.0.50727.5420 (Win7SP1.050727-5400) 9/29/2010 12:01 AM 000007FEE9120000-000007FEE996B000 [6264] DAccess_OLP.vshost.exe: Managed
System.Data.OracleClient.dll

C:\Windows\assembly\GAC_64\System.Data.OracleClient\2.0.0.0__b77a5c561934e089\System.Data.OracleClient.dll Yes N/A Cannot find or open the PDB file. 11 2.0.50727.5420 (Win7SP1.050727-5400) 9/29/2010 12:01 AM 000007FEEA040000-000007FEEA1B3000 [6264] DAccess_OLP.vshost.exe: Managed</pre>


All projects in my standalone Oraclient project are referencing the 64 bit libraries. So this seems to be why ASP.NET is reporting ' Attempt to load Oracle client libraries threw BadImageFormatException.'

The ASP.NET project is loading the 32 bit libraries of everything i specified and so is crashing....


How do I fix this? How do i specify the right libraries in the ASP.NET project? I did reference the 64 bit projects in ASP.NET originally. So why is the ASP.NET project loading all these 32 bit libraries.


Any help would be appreciated. Thanks
 
Share this answer
 
Solved!!!!


I've run it similar issues with the Oracle Data Access Components before. My guess is that you built your .exe using the AnyCPU platform target in your console application's build configuration. This means that when it's run on your 32-bit development machine it will be loaded into a 32-bit process whereas on the 64-bit server it will be loaded into a 64-bit process. The problem is that the Oracle.DataAccess.dll component comes in two different flavours, a 32-bit and 64-bit version. When you copied the 32-bit version into the deployment bin directory from your development machine, at runtime the application would try to load an assembly explicitly marked as 32-bit into a 64-bit process which doesn't work and explains why you get the System.BadImageFormatException.

So perhaps the best solution would be to explicitly target the 64-bit platform in your console app's project settings for the release configuration and reference the 64-bit version of Oracle.DataAccess.dll. On the server you either need the 64-bit Oracle.DataAccess.dll to be installed in the GAC (which it might have been when the ODAC was installed) or you need to deploy the 64-bit assembly with your application.

I've found this stuff to be a pain when you need to target both platforms.

For Any Reference please go through this link.
http://stackoverflow.com/questions/7851090/deploying-c-sharp-console-app-with-oracle-dataaccess-reference/7851988#7851988
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900