Learning While Aging

How to fix System.Data.OracleClient BadImageFormatException error

[UPDATE]: The fix in this post may not work on Windows Vista/7  64-bit operating system, if you are using Vista/7 and have the problem specified in this post, then check out the updated post here: https://learningpenguin.net/2010/08/13/update-how-to-fix-system-data-oracleclient-badimageformatexception-error/

If you use Microsoft’s OracleClient libraries to connect Oracle database in .NET application, you may encounter BadImageFormatException error if the application is running on a x64 machine. The actual error message shows as follows:

[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.]

You can follow the following steps to fix the error:

1. In Visual Studio, right click your project from the Solution Explorer and click “Properties”.

2. Click Compile tab on the left, then click Advanced Compile Options.

20090921_154148

3. From Target CPU drop down list, change Any CPU to x86.

20090921_154240_thumb

4. Click OK to accept the changes, then rebuild the application.

It should fix the above exception error.