Oracle.DataAccess – System.BadImageFormatException

Posted by Blake on 8/6/2013

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
    Message=Could not load file or assembly 'Oracle.DataAccess, Version=, 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=, 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.