.net x-64 机器上的 Oracle.DataAccess.Dll 加载问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28213678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:36:54  来源:igfitidea点击:

Oracle.DataAccess.Dll loading issue on x-64 machine

.netoracledll

提问by binu

I have a .net exe program which is using Oracle.DataAccess, Version=2.121.1.0 dll. My development machine and tfs build server both are 32-bit. Everything is working fine on 32 machines. But now I have to migrate this program on x64 (Windows Server 2012 R2) and my all problems started from there. I am getting the famous error Could not load file or assembly 'Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies..

我有一个使用 Oracle.DataAccess, Version=2.121.1.0 dll 的 .net exe 程序。我的开发机器和 tfs 构建服务器都是 32 位的。在 32 台机器上一切正常。但是现在我必须在 x64(Windows Server 2012 R2)上迁移这个程序,我的所有问题都从那里开始。我收到了著名的错误无法加载文件或程序集 'Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' 或其依赖项之一。.

I googled a lot and tried various things so far:

到目前为止,我用谷歌搜索了很多并尝试了各种方法:

  1. Specifically build the executeble to target X86 platform by changing the project properties Compile option
  2. I have installed the Oracle dll on the machine and it's successfully registered in the GAC
  3. Tried to build the executable to target 'Any CPU' and when it didn't work tried X64 as well
  4. Specifically supplied the assembly binding information in app.config file to look at the exact place for loading the dll.
  5. Turned on the Fusion log to see the exact failure cause
  1. 通过更改项目属性编译选项,专门构建针对 X86 平台的可执行文件
  2. 我已经在机器上安装了Oracle dll并且它在GAC中成功注册
  3. 试图构建可执行文件以定位“任何 CPU”,当它不起作用时也尝试了 X64
  4. 在 app.config 文件中专门提供了程序集绑定信息,以查看加载 dll 的确切位置。
  5. 打开 Fusion 日志以查看确切的失败原因

Please see the error log below:

请查看下面的错误日志:

29/01/2015 10:57:30;ALERT ;System.Exception caught in Main() 29/01/2015 10:57:30;ERROR ;System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: 'Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' at XXXX.Common.Components.OraDataAccess..ctor() at XXXX.Library.ValuesCore.ValuesCore..ctor() at XXXX.Library.DerivationsCore.Derivations..ctor() at XXXX.Processes.XXXX.Main.Main() === Pre-bind state information === LOG: User = XX LOG: DisplayName = Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342 (Fully-specified) LOG: Appbase = file:///D:/Release/ LOG: Initial PrivatePath = NULL Calling assembly : XXXX.CommonComponents, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e9b31bf34182bd8b. === LOG: This bind starts in default load context. LOG: Using application configuration file: D:\Release\XXXX.exe.Config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config. LOG: Post-policy reference: Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342 LOG: Attempting download of new URL file:///C:/Oracle/odp.net/bin/2.x/Oracle.DataAccess.dll. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated. 29/01/2015 10:57:30;ERROR ;Could not load file or assembly 'Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format. 29/01/2015 10:57:30;ALERT ;(Global) Point Source ID = 0, Calc Time = 29/01/2015 10:57:30. 29/01/2015 10:57:30;STOP ;

29/01/2015 10:57:30;ALERT ;System.Exception 在 Main() 中捕获 29/01/2015 10:57:30;ERROR ;System.BadImageFormatException: 无法加载文件或程序集 'Oracle.DataAccess, Version =2.121.1.0,Culture=neutral,PublicKeyToken=89b483f429c47342' 或其依赖项之一。试图加载格式不正确的程序。文件名:“Oracle.DataAccess,版本=2.121.1.0,Culture=neutral,PublicKeyToken=89b483f429c47342”在 XXXX.Common.Components.OraDataAccess..ctor() 在 XXXX.Library.ValuesCore.ValuesCore..ctor() 在 XXXX .Library.DerivationsCore.Derivations..ctor() at XXXX.Processes.XXXX.Main.Main() === 预绑定状态信息 === LOG: User = XX LOG: DisplayName = Oracle.DataAccess, Version=2.121 .1.0,Culture=neutral,PublicKeyToken=89b483f429c47342(完全指定)LOG:Appbase = file:///D:/Release/ LOG:初始 PrivatePath = NULL 调用程序集:XXXX.CommonComponents,版本=1.0.0.0,Culture=neutral,PublicKeyToken=e9b31bf34182bd8b。=== LOG:此绑定在默认加载上下文中启动。日志:使用应用程序配置文件:D:\Release\XXXX.exe.Config 日志:使用来自 C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config 的机器配置文件。日志:后政策参考:Oracle.DataAccess,版本=2.121.1.0,文化=中性,PublicKeyToken=89b483f429c47342 日志:正在尝试下载新的 URL 文件:///C:/Oracle/odp.net/bin/2.x /Oracle.DataAccess.dll。ERR: 未能完成装配设置 (hr = 0x8007000b)。探测终止。29/01/2015 10:57:30;错误;无法加载文件或程序集“Oracle.DataAccess,版本=2.121.1.0,Culture=neutral,PublicKeyToken=89b483f429c47342”或其依赖项之一。试图加载格式不正确的程序。29/01/2015 10:57:30;ALERT ;(全球)点源 ID = 0,计算时间 = 29/01/2015 10:57:30。29/01/2015 10:57:30;停止;

Any help would is desparately needed and will be greatly appreciated.

任何帮助都非常需要,将不胜感激。

Thanks

谢谢

回答by Wernfried Domscheit

The architecture (x86 or x64) of Oracle.DataAccess.dll must match the architecture of installed Oracle Client and both of them must match the architecture of your deployed application (i.e. whether you compiled at "AnyCPU" or "x86" or "x64").

Oracle.DataAccess.dll 的架构(x86 或 x64)必须与已安装的 Oracle Client 的架构相匹配,并且两者都必须与您部署的应用程序的架构相匹配(即,无论您是在“AnyCPU”还是“x86”或“x64”下编译) )。

"AnyCPU" will target to x64 on a 64-bit Windows.

“AnyCPU”将针对 64 位 Windows 上的 x64。

The best solution is to install both x86 and x64 Oracle Client (and according ODP.NET) on your machine, then any combination will work. Here is an instruction how to do this: Install Oracle x86 and x64

最好的解决方案是在你的机器上安装 x86 和 x64 Oracle Client(以及根据 ODP.NET),然后任何组合都可以工作。以下是如何执行此操作的说明:安装 Oracle x86 和 x64

An alternativ solution is to use the ODP.NET Managed Driver, this works in any case. You can download it from here: 64-bit Oracle Data Access Components (ODAC) Downloads

另一种解决方案是使用 ODP.NET 托管驱动程序,这在任何情况下都有效。您可以从这里下载:64 位 Oracle 数据访问组件 (ODAC) 下载