Could not load file or assembly ‘Oracle.DataAccess’ or one of its dependencies. An attempt was made to load a program with an incorrect format

I have installed a Web app on IIS 7.0 Windows Server 2008 R2 64bit.
I am referring an oracle.DataAccess.dll;
When I try to access the application I get the following message:
“Could not load file or assembly ‘Oracle.DataAccess’ or one of its dependencies. An attempt was made to load a program with an incorrect format.”
Can anybody help me, please?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

It seems the Oracle Data Access Component installation process using the “11.2 Release 3 (11.2.0.2.1) with Xcopy Deployment” version is broken. To fix this you must register the missing assemblies in the GAC. To do this for this specific version run these commands from within an administrator console:

md C:WindowsassemblyGAC_32Oracle.DataAccess4.112.2.0__89b483f429c47342

copy %ORACLE_HOME%odp.netbin4Oracle.DataAccess.dll C:WindowsassemblyGAC_32Oracle.DataAccess4.112.2.0__89b483f429c47342

md C:WindowsassemblyGAC_32Oracle.Web4.112.2.0__89b483f429c47342

copy %ORACLE_HOME%asp.netbin4oracle.web.dll C:WindowsassemblyGAC_32Oracle.Web4.112.2.0__89b483f429c47342

Note that this registers only the DLL’s but not other languages resources. So, if you are using any another language than English (de, es, fr, it, ja, ko, pt-BR, zh-CHS, and zh-CHT), then you need to register these as well using the corresponding resource file.

If you have Visual Studio installed on the machine, you can issue the following commands instead:

gacutil /i %ORACLE_HOME%odp.netbin4Oracle.DataAccess.dll
gacutil /i %ORACLE_HOME%asp.netbin4oracle.web.dll

Note: look for gacutil.exe under the Visual Studio installation folder for it.

Hope this helps.

P.S. Or you can try this.

Method 2

I avoided registering the 11.2 Release 5 assemblies in the GAC by setting “Enable 32-bit Applications” for the application pool to true.

Method 3

You may need to enable 32-bit applications in your AppPool.

http://www.alexjamesbrown.com/development/could-not-load-file-or-assembly-chilkatdotnet2-or-one-of-its-dependencies-an-attempt-was-made-to-load-a-program-with-an-incorrect-format/

Method 4

You need to register that dll on the live server using GAC util. Also check if its present in bin folder or not. Some times missing dll’s in bin directory results in same error

Method 5

In my case, I use VS 2010, Oracle v11 64 bits. I might to publish in 64 bit mode (Setting to “Any Cpu” mode in Web Project configuration) and I might set IIS on Production Server to 32 Bit compability to false (because the the server is 64 bit and I like to take advantage it).

Then to solve the problem “Could not load file or assembly ‘Oracle.DataAccess’” (sometime appear the “Compiler Error Message: CS1705: Assembly” error):

  • In the Local PC and Server is installed Oracle v11, 64 Bit.
  • In all Local Dev PC I reference to Oracle.DataAccess.dll (C:appuserproduct11.2.0client_1odp.netbin4) which is 64 bit.
  • In IIS Production Server, I set 32 bit compatibility to False.
  • The reference in the web project at System.Web.Mvc.dll was the version v3.0.0.1 in the local PC, however in Production is only
    instaled MVC version 3.0.0.0. So, the fix was locallly work with MVC
    3.0.0.0 and not 3.0.0.1 and publish again on server, and it works.

Method 6

Installing 64-bit ODAC 11.2 Release 3 (11.2.0.2.1) Xcopy for Windows x64 from:

http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html

Fixed it for me. Make sure to update your system path as per step #4 in the readme file.

Method 7

The accepted answer, published by George Netu helped to solve my problem, but I had to fiddle with some additional trifles:

Problem description:

Under C:Windowsassembly, I found two Oracle.DataAccess items(GAC-folders?). Relict, caused by several Oracle client installations. One item showed Version 2.112.1.0 but was actually version 2.121.2.0 (visible through Properties->Version). That inconsistency was the bug.

First unhelpful attempts:

  • tried to deinstall and reinstall the Oracle full client, both in versions Runtime/Administrator
  • tried to redeploy the correct .dlls
  • tried to copy the new installed assemblies in the GAC serveral times, as stated in the accepted answer above via command prompt (but that didn’t solve the version mismatch..)
  • tried to use gacutil /i ...

Final success:

I landed on the Gacutil.exe msdn page and were ultimately able to delete the items from the C:Windowsassembly folder.

gacutil /u Oracle.DataAccess, Version=2.112.1.0, Culture="Neutral",PublicKeyToken=45e343aae32233ca
gacutil /u Oracle.DataAccess, Version=2.212.2.0, Culture="Neutral",PublicKeyToken=45e343aae3223abc
gacutil /u Oracle.Web, Version=2.112.1.0, Culture="Neutral",PublicKeyToken=45e343aae3223def

After that, i repeated the two gacutil /i ... commands and the two dlls appeared there in consistent versions.

Finally restarted the IIS, and it works..

Method 8

Yeah, it is a quite annoying issue I faced sometimes. The main problem is that an web application uses wrongly 32 bit Oracle.DataAccess.dll instead of 64 bit, or in the reverse case. There are a few solutions for it.

1. Enabling 32-bit applications in the application pool if your application is 64 bit and need to run 32 bit Oracle.DataAccess.dll.

Go to the IIS and set true for “Enable 32-Bit Applications” option in Advanced Settings of an Application pool.

2. Correcting reference dll.

Reference path is supposed to be system reference path configured by Oracle Installation process. But, some cases such as installing or updating new Oracle version, the latest DLLs doesn’t update old ones, or path is changed, or a reference is not updated in the web application project. Therefore, we should correct Oracle.DataAccess reference manually.

Go to the web application and remove Oracle.DataAccess reference. And add new reference for Oracle.DataAccess. It must be correct Oracle.DataAccess.dll from your oracle installation path. For example:

C:Oracleproduct12.2.0client_1odp.netbin4Oracle.DataAccess.dll

ODP.NET and Dependent Unmanaged DLL Mismatch
To enforce the usage of
Oracle.DataAccess.dll assembly with the correct version of its
unmanaged DLLs, an exception is raised if Oracle.DataAccess.dll
notices it has loaded a mismatched version of a dependent unmanaged
DLL.

https://docs.oracle.com/cd/E11882_01/win.112/e23174/InstallODP.htm#ODPNT152

3. Easy and quick way (but not proper solution) to fix the issue is that override directly an Oracle.DataAccess.dll file copying from oracle installation path (for example: C:Oracleproduct12.2.0client_1odp.netbin4 ) to Bin folder of your web application.

Hope this helps you a little. Good luck.

Method 9

I had the same problem.

I go to the project properties in general section set platform target to 64 bit (x64) and my problem solved

Method 10

In application pool —> click Advance settings –> Enable 32 bit option

see the this image

Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x