BadImageFormatException while using Oracle Client 64 bit and Visual Studio 2010!
Asked Answered
C

11

23

One of our dev team member got an error

Attempt to load oracle client libraries threw BadImageFormatException

It seems

This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.

But it was me who configured the system - Here's the specifications:

  • Windows 7 64-bit
  • Visual Studio 2010 Premium
  • Oracle Client 11g R2 64Bit installed as Runtime

Any thoughts?

Couthie answered 3/5, 2011 at 13:11 Comment(3)
Have you upgraded to the latest ODAC Clent? oracle.com/technetwork/developer-tools/visual-studio/downloads/…Himelman
does it have any thing to do with Visual Studio being 32Bit ?Couthie
perhaps - I'm not acquainted with Visual Studio thoughHimelman
P
10

I have seen this a couple of times recently when running Visual studio on a 64Bit O/S. A simple workround is to install the 32bit client on your 64Bit development machine.

Regards, Pete

Proscenium answered 16/5, 2011 at 16:16 Comment(2)
Yes but you also need to make sure you app is using a 32-bit Application Pool. Open IIS Manager and click "Advanced Settings" on the Pool and then "Enable 32-Bit Applications=True". help.webcontrolcenter.com/KB/a1114/…Lagos
We attempted installing 32 bit along with 64 bit clients in separate Oracle homes on Windows Server 2012R2, however it didn't end well and we were forced to uninstall both, then re-install the 64 bit Client. Took several days to get everything to work again.Mussorgsky
S
20

I am sorry about adding a second answer but if you have 64 bit and 32 bit clients installed in the same machine you may encounter this problem too.

Two clients installed

C:\oracle\product\11.2.0\client32Bit
C:\oracle\product\11.2.0\client64Bit

Control your path Environment Variable. Which Oracle client is first, it is loaded before other one.

 echo %PATH%
 XXXX;C:\oracle\product\11.2.0\client64Bit\BIN;XXX

Since my 64bit Oracle Client is first in PATH, VS.NET tries to use it for Oracle Connections and throws Bad Image Exception.

  set PATH=C:\oracle\product\11.2.0\client32Bit\BIN;%PATH%
  REM Visual Studio 2008
  "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
  REM Visual Studio 2010
  "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"

After this you can connect oracle. Of course you can put 32Bit client first in path but I prefer to put 64 bit client before 32 bit for other applications.

Savannahsavant answered 15/12, 2011 at 13:49 Comment(1)
This is what solved the problem for me. Thanks for your help.Musgrove
T
11

Same problem you may face also in Visual Studio 2013 and 64-bit Oracle Client (11 and 12 versions). My solution is:

a) Desktop project. Project properties > Build > disable 'Prefer 32-bit' checkbox.

b) ASP.NET project or web site. Main menu > TOOLS > Options > Project and Solutions > Web Projects > enable 'Use the 64 bit version of IIS Express for web sites and projects' checkbox.

Trimly answered 29/4, 2015 at 19:15 Comment(2)
hi.. thank u.. answer (b) works for me.. i hate to install the 32 bit oracle along with 64 bit... this is for Visual Studio 2015Spectrum
Thank You, I got it working on Windows 10. I have WINDOWS.X64_193000_client installed. Using Visual Studio 2015 C# application, my application has platform target x64. Just enabling 'Use the 64 bit version of IIS Express for web sites and projects' checkbox, my .NET Web application works fine, and it would not work when I unchecked this checkbox.Salicin
P
10

I have seen this a couple of times recently when running Visual studio on a 64Bit O/S. A simple workround is to install the 32bit client on your 64Bit development machine.

Regards, Pete

Proscenium answered 16/5, 2011 at 16:16 Comment(2)
Yes but you also need to make sure you app is using a 32-bit Application Pool. Open IIS Manager and click "Advanced Settings" on the Pool and then "Enable 32-Bit Applications=True". help.webcontrolcenter.com/KB/a1114/…Lagos
We attempted installing 32 bit along with 64 bit clients in separate Oracle homes on Windows Server 2012R2, however it didn't end well and we were forced to uninstall both, then re-install the 64 bit Client. Took several days to get everything to work again.Mussorgsky
E
9

I had the same error after upgrading to Windows 7. I resolved it by changing the Platform target to x86 in the Build tab of the Properties page in Visual Studio

Edeline answered 14/10, 2013 at 13:46 Comment(1)
In my case, it was the opposite: changing my target platform to x64 fixed the problem.Unclassified
S
3

I changed 32 bit enabled support to FALSE in my Application pool in IIS7. This worked for me. I found it easy. Cheers :)

Sudor answered 8/3, 2013 at 11:0 Comment(0)
P
0

The quick and easy solution for this problem you have to follow the below steps only:

  1. Install ODACv11.2021Xcopy_x64, by run install.bat file then check "c:\oracle" as created path.
  2. copy your Network configuration folder [that contain admin folder with tnsnames.ora file] in oracle 32bit to "c:\oracle".
  3. Added the "c:\oracle" path to the PATH environment variable.

enjoy

Best Regards, Eng. Nawaf H. Bin Taleb.

Perceptible answered 17/2, 2013 at 17:51 Comment(0)
S
0

I got the same exception and I found out that it occurred when I upgraded to MVC version higher than 2.0., in my case MVC 4.0.

Creating a new project in MVC 2.0 resolved the issue.

Simpleton answered 27/6, 2013 at 11:15 Comment(0)
R
0

If you want to use 64 bit see my answer here:
64 bit Oracle DataAccess configuration

If you are content with 32 bit, just install the 32 bit version of Oracle Data Access Components. Since the development server of Visual Studio is 32 bit, you won't have any problems.

Runyon answered 18/7, 2013 at 11:1 Comment(0)
G
0

Simple solution: works for me. try this.

I spent almost 4 hours to find the solution for BadImageFormatException issue.

Scenario: VS 2012, i was trying to add entity model to Oracle database first time. I knew that there are two steps to add model for oracle database:

  1. Connect oracle database using server explore (where connection string will be created and which can be used while adding model)
  2. Add model using existing connectionstring (created in step1).

But i was struck in step 1 itself with BadImageFormatException warning and I found solution. Resolution:

  1. Follow the instruction given in link and complete the oracle client installation http://www.oracle.com/technetwork/topics/dotnet/whatsnew/vs2012welcome-1835382.html
  2. Once installation completed successfully, then simple step ie. add model to project. here use existing connection string from dropdownlist and provide userid/pwd.

then you are ready to use model :)

Grannias answered 28/3, 2015 at 22:47 Comment(0)
D
0

If you are running the application via Visual Studio, then set the 'Use the 64 bit version of IIS Express for websites and projects' checkbox to checked, by accessing the 'Web-projects' option under 'Projects and Solutions' in the Tools->Options menu in Visual Studio.

Dyspeptic answered 5/11, 2019 at 10:36 Comment(1)
N
-1

I had the same problem and that solution that Muru's shared worked to me:

http://www.oracle.com/technetwork/topics/dotnet/whatsnew/vs2012welcome-1835382.html

Just install ODAC and

Ningsia answered 23/2, 2017 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.