4

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..

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

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 ;

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

Thanks

tommybee
  • 2,409
  • 1
  • 20
  • 23
binu
  • 337
  • 2
  • 5
  • 16

1 Answers1

8

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").

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

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

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

Community
  • 1
  • 1
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • Hi Wernfried, thanks. One slight confusion, I believe the version of oracle.dataaccess.dll will be different in the x86 and x64 oracle client even if i create the symbolic link. My exe specifically looks for 'Oracle.DataAccess, Version=2.121.1.0' which exists only in 32-bit, how will I get this dll in the x64 version? Please let me know so that I can go ahead with your suggestion. – binu Jan 29 '15 at 13:34
  • I can not use 64-bit Oracle Data Access Components as my dev and build machine both are still on 32-bit mode. – binu Jan 29 '15 at 13:35
  • No, your exe searches `Oracle.DataAccess.dll` in your GAC (Global Assembly Cache). If your exe is x64 then `Oracle.DataAccess.dll` for x64 will be loaded. If this version does not exist, it will fail. The `ODP.NET Managed Driver` works also on x86 (32 bit) without any problem. – Wernfried Domscheit Jan 29 '15 at 14:13
  • Thanks, so are you suggesting that I should install ODP.NET Managed Driver on all the machines i.e Development, Build and Deployement and that will sort out the version conflict? – binu Jan 29 '15 at 14:25
  • Yes, actually there is nothing to install. Just copy the `Oracle.ManagedDataAccess.dll` to the application folder, that's it. – Wernfried Domscheit Jan 29 '15 at 14:33