Home Ask Login Register

Developers Planet

Your answer is one click away!

Umit Gunduz February 2016

asp.net core Oracle.DataAccess System.BadImageFormatException: Could not load file or assembly Oracle.DataAccess

I've added Oracle.DataAccess as reference to asp.net core project. I've only installed Oracle Data Provider for .Net when installed ODAC. I would like to make a simple example with Dapper on the project.

public class Program
    const string connectionString = "xxxxx";
    public static void Main(string[] args)
        IDbConnection connection = new OracleConnection(connectionString);
        string sql = "SELECT * FROM People WHERE  Name='JOHN'";
        var r = connection.Query<People>(sql);

The application wasn't running. I was getting this error below when I tried "dnx run" on the project folder.

System.BadImageFormatException: 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.

If you get this message, probably, it means Oracle.DataAccess dll doesn't exist in the GAC.

  1. Open Command Line and go to bin folder under the odp.net e.g.

    cd C:\oracle\product\12.1.0\client_x86\odp.net\bin\4

  2. Run this command below

    OraProvCfg.exe /action:gac /providerpath:C:\oracle\product\12.1.0\client_x86\odp.net\bin\4\Oracle.DataAccess.dll

After doing these steps I was able to run the project successfully.


Joe Audette February 2016

BadImageFormat means the dll is not compatible with the runtime.

Problem is that Oracle has not yet released a driver compatible with .NET Core.

You could still use the currently available driver in ASP.NET Core, but only when you run it on the full desktop .NET framework, not on the .NET Core Framework.

What you should be able to do to solve this is simply remove the dnxcore50 target from your project.json file so that you are only targeting the desktop framework.

Doing that means you can only run on windows for now, but later when Oracle releases a compatible driver you could then have the option to target .NET Core framework.

Post Status

Asked in February 2016
Viewed 2,680 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life