Oracle.DataAccess – System.BadImageFormatException


So you've wired up your .Net app, added your references for Oracle.DataAccess only to find that when you start your application you get a System.BadImageFormatExeption that might look something like this:

System.BadImageFormatException was unhandled
HResult=-2147024885
Message=Could not load file or assembly 'Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format.
FileName=Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342

In this case you probably have a mismatch between your Oracle drivers and what your project is setup to compile as (e.g. x86, x64, AnyCPU). If you have 32-bit Oracle drivers then x64 won't work and AnyCPU may or may not work depending on your workstation (if it's a 32-bit workstation it would work, if it was 64 and defaulted to that it wouldn't).

The solution here is to specifically set your executable, website or assembly to compile for the same architecture as the Oracle.DataAcess file you're using. In my case, it's 32-bit so I'm specifically go into the project settings and change my assembly to compile for x86. Problem solved.

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.