Anjali5
Anjali5

Reputation: 683

Could not load file or assembly "Oracle.DataAccess" or one of its dependencies

I am trying to run this web application. I keep getting this error "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." Exception details: System.BadImageFormatException. "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." Below are the things that I already tried.

  1. replaced all the oracle dll's with 32 bit oracle dll i.e 2.112.3.0

I have 32 bit client installed on 64 bit machine. The operating system is windows 7.

  1. compile each individual project individually. Deleted all the oracle dependent files dll and then added the 2.112.3.0 dll's individually and then compiled each project

  2. Register the 32 bit dll on GAC using this statement gacutil /i %ORA_HOME4%\odp.net\bin\4\Oracle.DataAccess.dll

gacutil /i %ORA_HOME4%\asp.net\bin\4\oracle.web.dll

for the above two statements, I copied the gacutil.exe from c:\Program Files(x86)\Microsoft sdk\windows\v7.0A\Bin\NETFX4.0 Tools\X64 to C:\ drive and then

I executed the above two statement:

gacutil /i %ORA_HOME4%\odp.net\bin\4\Oracle.DataAccess.dll gacutil /i %ORA_HOME4%\asp.net\bin\4\oracle.web.dll when I executed the above two statements, I didn't get any message, I executed them in Dos windows under administrator privilege.

  1. I also deleted all the Temporary ASP.net files from this location

c:\windows\Microsoft.Net\V4.0.30319\temporary ASP.net files I also changed the web application build Platform target to X86, Originally, it was at "ANy CPU". out of frustration, I also tried changing the platform target to X64 and then I got the error message saying

" Cold not load file or assemble . webapp" or one of its dependencies. An attempt was made to load a program with an incorrect format.

I don't have IIS installed on my computer, I am running this application in visual studio 2010 so I think it will be using the inbuilt IIS that comes with visual studio.

I spend lot of hours resolving this issue, but still getting the same error again and again.

Upvotes: 54

Views: 245582

Answers (13)

Mohammed EL KALAKHI
Mohammed EL KALAKHI

Reputation: 169

In my case I had a console application, I just unchecked Prefer 32-bit on Build projet properties tab and then I add this to my app.config:

<runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="2.112.1.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>

Upvotes: 1

Jeff Mergler
Jeff Mergler

Reputation: 1512

I had the same error with Oracle.DataAccess but deploying to Azure Web Sites (azurewebsites.net). For me I had to edit a setting in VS.NET 2019 before publishing to Azure. I ticked the checkbox "Use the 64 bit version of IIS Express for Web sites and projects" which is found under Tools > Options > Projects and Solutions > Web Projects.

Upvotes: 6

Abdul Rehman Kaim Khani
Abdul Rehman Kaim Khani

Reputation: 1170

i Have face the same issue and resolved by replacing the old Oracle.DataAccess.dll with new Oracle.DataAccess.dll(which come with oracle client when install)

in my case the path of new Oracle.DataAccess.dll is

  • E:\app\Rehman.Rashid\product\11.2.0\client_1\ODP.NET\bin

Upvotes: 2

Anthony De Souza
Anthony De Souza

Reputation: 554

I needed a 64-bit version of oracle.dataaccess.dll but this caused problems with other libraries I was using.

[BadImageFormatException: 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 followed several steps above. Going to advance settings on the projects pool to toggle allow 32bit worked but I wasn't content to leave it like that so i turned it back on.

My project also had references that relied on Elmah and log4net references. I downloaded the latest version of these and my project was able to build and run fine without messing with the pools's allow 32bit setting.

Upvotes: 1

ADH
ADH

Reputation: 3071

If you are using IIS Express and VS 2017:

Go to the Web Application Properties > Web Tab > Servers Section > And change the Bitness to x64.

Upvotes: 14

Biki
Biki

Reputation: 2588

For me everything else was almost ok, but somehow my project settings changed & iisExpress was getting used instead of IISLocal. When I changed & pointed to the virtual directory (in IISLocal), it stared working perfectly again.

Upvotes: 1

Kifayat Ullah
Kifayat Ullah

Reputation: 619

You may need to enable 32-bit applications in your AppPool. Go to > 'Application Pool' in IIS => right click your app pool => advance setting => 'enable 32 bit application' to true.

Please don't forget to restart your app pool and your corresponding application pointing to that app pool.

Upvotes: 18

KriZ
KriZ

Reputation: 682

Had the issue again when i moved from one machine to another and had everything reinstalled. In my case, i'm using both 32bit and 64bit Oracle ODP.NET installs.

When listing the assemblies on my new machine i ended up with the following list

 C:\oracle\product\11.2.0\X64\odp.net\bin\4>gacutil /l|findstr Oracle.DataAccess
     Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
     Policy.2.102.Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
     Policy.2.111.Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
     Policy.2.112.Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
     Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
     Policy.4.112.Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64

only 64bit DLLs to be seen here.

enter image description here

I couldn't see it from the web.config but the one i was using was a 32bit version.

When checking my old machine with the GACutil, i saw more DLLs, also the X86 ones.

Fixed by reapplying the registration process(both x32/x64 version referenced here)

OraProvCfg.exe /action:gac /providerpath:C:\oracle\product\11.2.0\x32\ODP.NET\bin\4\Oracle.DataAccess.dll

OraProvCfg.exe /action:gac /providerpath:C:\oracle\product\11.2.0\x64\ODP.NET\bin\4\Oracle.DataAccess.dll

after that , Visual Studio was a happy bunny and compiled everything again for me.

Upvotes: 6

Atiq Baqi
Atiq Baqi

Reputation: 652

In my case the following solved the problem:

  1. Downloading the "32-bit Oracle Data Access Components (ODAC) with Oracle Developer Tools for Visual Studio" from http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html
  2. Then adding reference oracle.dataaccess.dll to the bin file by browsing the file location or just from the refence list in .NET tab.

Upvotes: 3

Hernaldo Gonzalez
Hernaldo Gonzalez

Reputation: 2046

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'":

  • In the Local PC and Server is installed Oracle v11, 64 Bit.
  • In all Local Dev PC I reference to Oracle.DataAccess.dll (C:\app\user\product\11.2.0\client_1\odp.net\bin\4) 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.

Upvotes: 2

Sunil
Sunil

Reputation: 2905

Also you can download and execute the install.bat file in 'ODAC112030Xcopy.zip' from 64-bit Oracle Data Access Components (ODAC) Downloads. This resolved my problem.

Upvotes: 1

Saikat Daripa
Saikat Daripa

Reputation: 301

I found the solution with following steps:

  • remove the Oracle.DataAcces.dll reference,
    and add a fresh reference to:
    C:\windows\assembly\GAC\Oracle.DataAccess\X.XXX.X.XX__89b483f429c47342/oracle.dataaccess.dll
  • Make local copy= false.

Hope it helps

Upvotes: 30

user3048209
user3048209

Reputation: 509

Try this: Open IIS Manager, change application pool's advance setting, change Enable 32 bit Application to false.

Upvotes: 50

Related Questions