asp.net核心Oracle.DataAccess System.BadImageFormatException:无法加载文件或程序集Oracle.DataAccess [英] asp.net core Oracle.DataAccess System.BadImageFormatException: Could not load file or assembly Oracle.DataAccess

查看:532
本文介绍了asp.net核心Oracle.DataAccess System.BadImageFormatException:无法加载文件或程序集Oracle.DataAccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了Oracle.DataAccess作为对asp.net核心项目的引用. 安装ODAC时,我仅安装了.Net的Oracle数据提供程序. 我想用Dapper在该项目上做一个简单的例子.

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);
    }
}

该应用程序未运行.当我在项目文件夹上尝试"dnx run"时,出现以下错误.

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

System.BadImageFormatException:无法加载文件或程序集 'Oracle.DataAccess,版本= 4.121.2.0,区域性=中性, PublicKeyToken = 89b483f429c47342'或其依赖项之一.一个 试图加载格式不正确的程序.

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.

如果收到此消息,则可能意味着GAC中不存在Oracle.DataAccess dll.

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

  1. 打开命令行并转到odp.net下的bin文件夹,例如

  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

在下面运行此命令


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.

推荐答案

BadImageFormat表示dll与运行时不兼容.

BadImageFormat means the dll is not compatible with the runtime.

问题在于Oracle尚未发布与.NET Core兼容的驱动程序.

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

您仍然可以在ASP.NET Core中使用当前可用的驱动程序,但只有在完整的桌面.NET框架(而不是.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.

您应该能够执行的操作只是从您的project.json文件中删除dnxcore50目标,以便仅针对桌面框架.

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.

这样做意味着您现在只能在Windows上运行,但是稍后Oracle发布兼容的驱动程序时,您可以选择以.NET Core框架为目标.

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.

这篇关于asp.net核心Oracle.DataAccess System.BadImageFormatException:无法加载文件或程序集Oracle.DataAccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆