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

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

我有一个 .net exe 程序正在使用 Oracle.DataAccess,版本=2.121.1.0 dll。

我的开发机器和 tfs 构建服务器都是 32 位的。 在 32 台机器上一切正常。 但是现在我必须在 x64 (Windows Server 2012 R2) 上迁移这个程序,我的所有问题都从那里开始。

我遇到了著名的错误

无法加载文件或程序集 'Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' 或其依赖项之一。

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

 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

请查看下面的错误日志:

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 ;

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

谢谢

Oracle.DataAccess.dll 的体系结构(x86 或 x64)必须与已安装的 Oracle Client 的体系结构相匹配,并且它们都必须与您部署的应用程序的体系结构相匹配(即您是否在 "AnyCPU" 或"x86" 或 "x64").

"AnyCPU" 将以 64 位 Windows.

上的 x64 为目标

最好的解决方案是在您的计算机上同时安装 x86 和 x64 Oracle Client(并根据 ODP.NET),然后任何组合都可以。以下是如何执行此操作的说明:Install Oracle x86 and x64

另一种解决方案是使用 ODP.NET 托管驱动程序,这在任何情况下都有效。您可以从这里下载:64-bit Oracle Data Access Components (ODAC) Downloads