0

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=4.121.2.0, 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.

Umit Gunduz
  • 11
  • 1
  • 2
  • And was is your problem? Obviously you solved the problem, so why do you ask? There can be several reasons why ODP.NET does not work, see here: http://stackoverflow.com/questions/659341/the-provider-is-not-compatible-with-the-version-of-oracle-client – Wernfried Domscheit Feb 08 '16 at 14:14
  • As I recall, this error will occur also if your site is setup to run in 64-bit mode. Used to have to tell IIS to allow 32-bit components. That may not bit an issue here since DNX runs in it's own process. – b.pell Feb 08 '16 at 22:10

1 Answers1

1

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.

Joe Audette
  • 28,887
  • 11
  • 87
  • 93