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


I am getting this error while on of my .Net application are trying to make a connection to oracle database.

The error says that This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.. But I have made sure many times that the client installed in x64 bit not 32.

Date Time: 6/8/2014 10:57:55 AM: System.InvalidOperationException: 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. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
       at System.Data.Common.UnsafeNativeMethods.OCILobCopy2(IntPtr svchp, IntPtr errhp, IntPtr dst_locp, IntPtr src_locp, UInt64 amount, UInt64 dst_offset, UInt64 src_offset)
       at System.Data.OracleClient.OCI.DetermineClientVersion()
       --- End of inner exception stack trace ---
       at System.Data.OracleClient.OCI.DetermineClientVersion()
       at System.Data.OracleClient.OracleInternalConnection.OpenOnLocalTransaction(String userName, String password, String serverName, Boolean integratedSecurity, Boolean unicode, Boolean omitOracleConnectionName)
       at System.Data.OracleClient.OracleInternalConnection..ctor(OracleConnectionString connectionOptions)
       at System.Data.OracleClient.OracleConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
       at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
       at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
       at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
       at System.Data.OracleClient.OracleConnection.Open()
       at CustomizedSetupInstaller.Runscripts.InitializeDBObjects(String connectionString, String dbProvider)
asked on Stack Overflow Jun 8, 2014 by Maven • edited May 23, 2017 by Community

21 Answers


One solution is to install both x86 (32-bit) and x64 Oracle Clients on your machine, then it does not matter on which architecture your application is running.

Here an instruction to install x86 and x64 Oracle client on one machine:

Assumptions: Oracle Home is called OraClient11g_home1, Client Version is 11gR2

  • Optionally remove any installed Oracle client (see How to uninstall / completely remove Oracle 11g (client)? if you face problems)

  • Download and install Oracle x86 Client, for example into C:\Oracle\11.2\Client_x86

  • Download and install Oracle x64 Client into different folder, for example to C:\Oracle\11.2\Client_x64

  • Open command line tool, go to folder %WINDIR%\System32, typically C:\Windows\System32 and create a symbolic link ora112 to folder C:\Oracle\11.2\Client_x64 (see commands section below)

  • Change to folder %WINDIR%\SysWOW64, typically C:\Windows\SysWOW64 and create a symbolic link ora112 to folder C:\Oracle\11.2\Client_x86, (see below)

  • Modify the PATH environment variable, replace all entries like C:\Oracle\11.2\Client_x86 and C:\Oracle\11.2\Client_x64 by C:\Windows\System32\ora112, respective their \bin subfolder. Note: C:\Windows\SysWOW64\ora112 must not be in PATH environment.

  • If needed set your ORACLE_HOME environment variable to C:\Windows\System32\ora112

  • Open your Registry Editor. Set Registry value HKLM\Software\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME to C:\Windows\System32\ora112

  • Set Registry value HKLM\Software\Wow6432Node\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME to C:\Windows\System32\ora112 (not C:\Windows\SysWOW64\ora112)

  • You are done! Now you can use x86 and x64 Oracle client seamless together, i.e. an x86 application will load the x86 libraries, an x64 application loads the x64 libraries without any further modification on your system.

  • Probably it is a wise option to set your TNS_ADMIN environment variable (resp. TNS_ADMIN entries in Registry) to a common location, for example TNS_ADMIN=C:\Oracle\Common\network.

Commands to create symbolic links:

cd C:\Windows\System32 mklink /d ora112 C:\Oracle\11.2\Client_x64 cd C:\Windows\SysWOW64 mklink /d ora112 C:\Oracle\11.2\Client_x86


Both symbolic links must have the same name, e.g. ora112.

Despite of their names folder C:\Windows\System32 contains the x64 libraries, whereas C:\Windows\SysWOW64 contains the x86 (32-bit) libraries. Don't be confused.

answered on Stack Overflow Jun 9, 2014 by Wernfried Domscheit • edited Jul 3, 2018 by Wernfried Domscheit

In my situation, the Oracle 11.2 32-bit client was installed on my 64-bit Windows 2008 R2 OS.

My solution: In the Advanced Settings for the Application Pool assigned to my ASP.NET application, I set Enable 32-Bit Applications to True.

Please see below for the standalone .ashx test script that I used to test the ability to connect to Oracle. Before making the Application Pool change, its response was:

[Running as 64-bit] Connection failed.

...and after the Application Pool change:

[Running as 32-bit] Connection succeeded.

TestOracle.ashx – Script to Test an Oracle Connection via System.Data.OracleClient:

To use: Change the user, password and host variables as appropriate.

Note that this script can be used in a standalone fashion without disturbing your ASP.NET web application project file. Just drop it in your application folder.

<%@ WebHandler Language="C#" Class="Handler1" %>
<%@ Assembly Name="System.Data.OracleClient, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" %>

using System;
using System.Data.OracleClient;
using System.Web;

public class Handler1 : IHttpHandler
    private static readonly string m_User = "USER";
    private static readonly string m_Password = "PASSWORD";
    private static readonly string m_Host = "HOST";

    public void ProcessRequest(HttpContext context)
        context.Response.ContentType = "text/plain";

        string result = TestOracleConnection();

    public bool IsReusable
        get { return false; }

    private string TestOracleConnection()
        string result = IntPtr.Size == 8 ?
            "[Running as 64-bit]" : "[Running as 32-bit]";

            string connString = String.Format(
              "Data Source={0};Password={1};User ID={2};",
              m_Host, m_User, m_Password);

            OracleConnection oradb = new OracleConnection();
            oradb.ConnectionString = connString;
            result += " Connection succeeded.";
            result += " Connection failed.";

        return result;
answered on Stack Overflow Sep 29, 2014 by DavidRR • edited Sep 29, 2014 by DavidRR

I had the same issue on a Windows 10 PC. I copied the project from my old computer to the new one, both 64 bits, and I installed the Oracle Client 64 bit on the new machine. I got the same error message, but after trying many solutions to no effect, what actually worked for me was this: In your Visual Studio (mine is 2017) go to Tools > Options > Projects and Solutions > Web Projects

On that page, check the option that says: Use the 64 bit version of IIS Express for Websites and Projects

answered on Stack Overflow May 25, 2017 by Amir Tofighi

To revise IIS

  1. Select Application Pools.
  2. Clic in ASP .NET V4.0 Classic.
  3. Select Advanced Settings.
  4. In General, option Enable 32-Bit Applications, default is false. Select TRUE.
  5. Refresh and check site.


Platform: Windows Server 2008 R2 Enterprise - 64Bit - IIS 7.5

answered on Stack Overflow Oct 5, 2015 by javier maffla • edited Oct 5, 2015 by statox

As it was pointed out in the comments, System.Data.OracleClient is deprecated. There is little reason to start using it so late in the game.

Also as pointed out in the comments (I've marked this as community wiki in observence), there is now a managed provider as part of the 12c and later versions of the package. This provider does NOT require any unmanaged dlls so this should be a non issue in that case.

If you would prefer to use the old unmanaged Oracle.DataAccess provider from oracle, the simplest solution is to set the "DllPath" configuration variable:

<?xml version="1.0" encoding="utf-8" ?>
    <add key="DllPath"            value="C:\oracle\bin"/>

See "Search Order for Unmanaged DLLs" in for more information

answered on Stack Overflow Feb 18, 2015 by b_levitt

this solution work for me ,

To revise IIS

Select Application Pools.
Clic in ASP .NET V4.0 Classic.
Select Advanced Settings.
In General, option Enable 32-Bit Applications, default is false. Select TRUE.
Refresh and check site.


Platform: Windows Server 2012 Standart- 64Bit - IIS 8

answered on Stack Overflow Mar 10, 2016 by theozdemir

I had the same problem in SSIS 2008. I tried to connect to an Oracle 11g using ODAC 12c 32 bit. Tried to install ODAC 12c 64 bit as well. SSIS was actually able to preview the table but when trying to run the package it was giving this error message. Nothing helped. Switched to VS 2013, now it was running in debug mode but got the same error when the running the package using dtexec /f filename. Then I found this page:

To make it short it says: (if the page is still there just go to the page and follow the instrucrtions...) 1) Download and install the latest version of odac 64 bit xcopy from oracle site. 2) Download and install the latest version of odac 32 bit xcopy from oracle site. How? open a cmd shell AS AN ADMINSTARTOR and run: c:\64bitODACLocation> install.bat oledb c:\odac\odac64. the first parameter is the component you want to install. The second param is where to install to. install the 32 version as well like this: c:\32bitODACLocation> install.bat oledb c:\odac\odac32. 3) Change the path of the system to include c:\odac\odac32; c:\odac\odac32\bin; c:\odac\odac64;c:\odac\odac64\bin IN THIS ORDER. 4) Restart the machine. 5) make sure you have the same tnsnames.ora in both odac32\admin\network and odac64\admin\network folders (or at least the same entry for your connection). 6) Now open up SSIS in visual studio (I used the free 2013 version with the ssis package) - Use OLEDB and then select the Oracle Provider for OLE DB provider as your connection type. Set the name of the entry in your tnsnames.ora as the "server or file name". Username is your schema name (db name) and password is the password for schema. you are done!

Again, you can find the very detailed solution and much more in the original site.

This was the only thing which worked for me and did not mess up my environment.

Cheers! gcr

answered on Stack Overflow May 1, 2016 by gcr • edited May 8, 2016 by gcr

I developed desktop application using with 2.0 framework along with for connecting oracle db and I was facing similar error message ,"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."

following solutions were applied

  • Project, properties, Build TAB, select platform target : x86
  • Project, clean build, ReBuild solution
  • Install Oracle 11G*32 bit client

now, it work because application is set for 32bit and oracle 32bit client installed over Win2012 R2 server, hopefully will work for you.

answered on Stack Overflow Nov 22, 2017 by QSS

I had this error in my DNN application installed on Windows 2012 R2. It's using some 32 bit dll and only Oracle.DataAccess.dll x32 was working. My solution is:

  1. Uninstall old Oracle Client \ ODAC.
  2. Install Oracle 11 Client x32.
  3. Install Oracle ODAC 12 x64.
  4. Check IIS Application Pool (Classic version) has option "Enable 32-Bit Applications" = true.
answered on Stack Overflow Feb 14, 2019 by Mykola Boyko

Make Enable32bit Application to TRUE in the IIS App pool which you are consuming

answered on Stack Overflow Sep 11, 2019 by Santhosh

BadImageFormatException occures when a 32bit (x86) dll calls a 64bit dll or vice versa. If using AnyCPU for your entry executable then when run on a 64bit machine it will run as 64bit, however if that then calls a 32bit dll you get the exception which is why AnyCPU isn't always the answer.

I tend to build everything as 32bit (x86) as we still have to interface with some old components done in VB6 (32bit (x86)). While performance might be better for 64bit machines if we where to build in AnyCPU reliability is more important for us.

I would suggest trying to build all you components in 32bit (x86), unless you are doing some really intensive stuff I doubt it will make much difference.

answered on Stack Overflow Jun 9, 2014 by apc

As apc mentioned that error occurs "when a 32bit dll calls a 64bit dll or vice versa". The problem is that if you have build using AnyCPU and are running on a 64bit environment then the application will run as 64bit. If rebuilding explicitly for 32 and 64 bit is not an option then you could use a microsoft utility called corflags.exe which comes with the Windows SDK. Basically, you can modify a flag in the exe of the program you are executing to tell it to run as 32bit even if the environment is 64bit.

See here for information on using it

answered on Stack Overflow Sep 30, 2014 by Tomás

I would like to add a resolution that worked for me. Setup: Oracle 11g 64 bits running on Windows 2008 R2 (64 bits OS)

Client is a .net framework 3.5 application (ported from 2.0) compiled with x86 platform setting.

I had the exact same issue of BadImageFormatException. Compiling to 64 bits eliminates the exception but it was not an option for me as my app is using 32 bits activex components who do not work in 64 bits.

I solved the issue by downloading Oracle Instant Client 11 (this is just a bunch of DLL than can be xcopied) from Oracle website, and copying the files in my application files directory. See here :

This has solved the issue, from ProcMon tool I can see that the locally copied oci.dll gets loaded by System.Data.OracleClient and everything is fine.

It could probably be done by changing environment settings like proposed above, but this method has the advantage of not altering any settings on the server configuration.

answered on Stack Overflow Sep 2, 2015 by Pascal

I got this issue for a console Application.

In my case i just changed the Platform Target to "Any CPU" which you can see when you right click your solution and click on properties , you will find a Tab "Build" click on it, you will see "Platform target:" change it to "Any CPU", which will solve your issue

answered on Stack Overflow Jan 15, 2016 by user3559374 • edited Jun 19, 2019 by user3559374

Mine is the console application (it should work for the windows application as well) and I had same problem. To solve it I used PlatformTarget as x64 as my System.Data.OracleClient.dll (64 bit file) is at C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5. This will explicitly use 64 bit version of Oracle Client. This might help you if your solution works only on 64bit and if you are not using 32 bit dlls like dlls made in VB. I hope it will help you.

answered on Stack Overflow Mar 4, 2017 by Vikas • edited Mar 4, 2017 by Vikas

Please download the correct version of Oracle Client like Oracle Client 11.2 32-Bit; which resolved the problem for me.

answered on Stack Overflow Sep 8, 2017 by Raghu

I was also getting the same error I checked it my system was in 64 bit and I was using oracle.DataAccess of 32 bit version I added correct 64 version now it got resolved below path for the ref of Oracle.DataAccess.dll

Correct path for 64 bit OS- C:\Oracle\11g_64\product\11.2.0\client_64\\bin\4\Oracle.DataAccess.dll

Correct path for 32 bit OS- C:\Oracle\11g_32\product\11.2.0\client_64\\bin\4\Oracle.DataAccess.dll

answered on Stack Overflow Oct 10, 2018 by Ratnesh Sahu • edited Oct 10, 2018 by Suraj Rao

I had the same issue, then I fix it by change configuration manager x86 -> x64 and build


answered on Stack Overflow Oct 27, 2020 by Le Linh • edited Oct 27, 2020 by francisco neto

Make sure that registry HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\ODP.NET\4.112.# DIIPath key is pointing to 32 bit Oarcle client BIN directory. For example, DIIPath value can be C:\app\User_name\11.2.0\client_32bit\bin

answered on Stack Overflow Jul 17, 2017 by vladimir

For ssis 2008, just active 32bit run, bellow Image ( click on this link ) Orcale ssis 2008

answered on Stack Overflow Sep 29, 2020 by korbobolla • edited Sep 29, 2020 by Krzysztof Madej

Just build your code in x86 mode not in AnyCpu.

answered on Stack Overflow Sep 30, 2015 by Arno

User contributions licensed under CC BY-SA 3.0