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

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?

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:\Windows\assembly\GAC_32\Oracle.DataAccess\4.112.2.0__89b483f429c47342\
copy %ORACLE_HOME%\odp.net\bin\4\Oracle.DataAccess.dll C:\Windows\assembly\GAC_32\Oracle.DataAccess\4.112.2.0__89b483f429c47342\
md C:\Windows\assembly\GAC_32\Oracle.Web\4.112.2.0__89b483f429c47342\
copy %ORACLE_HOME%\asp.net\bin\4\oracle.web.dll C:\Windows\assembly\GAC_32\Oracle.Web\4.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.net\bin\4\Oracle.DataAccess.dll
gacutil /i %ORACLE_HOME%\asp.net\bin\4\oracle.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.

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

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/

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

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

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.

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:\Windows\assembly, 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:\Windows\assembly 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..

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:\Oracle\product\12.2.0\client_1\odp.net\bin\4\Oracle.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:\Oracle\product\12.2.0\client_1\odp.net\bin\4\ ) to Bin folder of your web application.
Hope this helps you a little. Good luck.

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

In application pool ---> click Advance settings --> Enable 32 bit option
see the this image

Related

unable to load dll error shown for one website and not the other copied website, both hosted on same IIS 7.0

I have a 3rd party dll which when used in my local VS was working perfectly without any issues. This 3rd party dll came with 32bit and 64 bit dll installation files. I ran the 64bit installer and the system32 folder had the dll required. My local project had no trouble calling these dll's.
When I tried the same step to host the website on IIS 7.0 on 64bit windows 2012 R2 testing server, I was getting the following error :
Unable to load DLL '3rdparty.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
To fix this i tried uninstalling the 64bit and installed the 32 bit dll's and SysWow64 had the dll's required and no error was received.
I checked if system32 had those dlls but there was none and only syswow64 had the dll's. Can any one tell me why 32 bit dll's worked on the server and 64bit on my local ?
Also when trying on different machines I found 32 bit installer worked on all but 64 bit had issues on some machines.
Adding to this strangeness, when I hosted a copy of same website on different folder however under same application pool of IIS 7.0 on the testing server. I received the error on one website while the other had no issue loading the dll's required. Both these website had everything same in terms of IIS user used, access rights only difference was they were under different folder structure.
Also is there any way of referencing 3rd party dll to use particular path rather than trusting system32 and syswow64 folders in website projects.
As mentioned by Cyril I used Procmon to track where the asp.net website was looking for the 3rd party dll. On checking it was found that 3rd party dll was being looked at SysWow64 folder rather than on anticipated folder that is System32. This was happening because the website before copying was compiled on 32 bit version and hence copied version was looking for 32 bit and not 64 bit. This was making it to behave differently. However I need to understand how does the .net compiler decide to use which version to get to the bottom of this confusion that I have.
Following question also helped: Dll in both the bin and the gac, which one gets used?

Could not load file or assembly System.Data.SQLite - Web App deployed

i know this is a duplicate question but i can't figure it out.
The Error Message:
Could not load file or assembly 'System.Data.SQLite' or one of it's
dependencies. An attempt was made to load a program with an incorrect
format.
The Context:
I am using VS2012, MVC4, .Net 4.5 to build a web application.
The application uses an other solution which contains the SQLite.dll with copy local.
I tried to deploy my web application on a Win2008 R2 server but i get the above error message.
I compile for Any CPU my dev. enviroment is Win7 x64 and my server also x64
What i tried:
1. Tried copying the msvcr100.dll to the deployed bin folder because it it a dependency of the SQLite
2. Tried to copy to the bin folder the SQLite.dll and the SQLite.Linq.dll from my dev. enviroment
3. Tried setting Enable 32 - Bit Applications" to false and also true for the app pool that i am using in IIS 7.5
4. Tried to restart IIS, added the Network Service and IIS user to have access to my folder.
5. Followed this post System.IO.FileLoadException: Could not load file or assembly 'System.Data.SQLite, I use the version V1.0.88 which is now a pretty old version which i guess was cleaned, maybee i should try and even older version?
You are running SQLite in 64 bit OS, try use x64 version of System.Data.SQLite.DLL
Download: http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

Oracle.DataAccess.dll can not be located though it exists

When I browse ASP.Net application developed in Visual Studio 2008 on IIS 7.5(Windows Server 2008 R2 x64) I get configuration error stating that Oracle.DataAccess, Version=2.111.7.20 file could not be located. I've already installed Oracle Data Provider for .NET which contains the file. When I setup ODP.net it places the dll files into c:\app....\odp.net\PublisherPolicy folder. I just in case copied those files to C:\Windows\Microsoft\Framework folder too, but still I got the same error. Could someone please help me solve this issue? Any help is greatly appreciated
The ODP.NET installation can be very tricky. There are many things that can go wrong:
You can have a version mismatch (2.111.7.20 vs 2.112.1.0 vs. 2.112.2.0).
You can have a mismatch between 32 and 64 bit.
The .NET DLL might exists but one of the dependencies is not found.
Try to check the 32/64 bit mismatch first. In IIS, you can configure whether your web application runs as 32 or 64 bit. To check it, have a look at the task manager and see whether the w3wp.exe process has the *32 mark. Then go to C:\Windows\Assembly in the file explorer. It's a special view that display the GAC. If it says x86 in the last column on the row Oracle.DataAccess, then it's 32 bit. If it says AMD64, then it's 64 bit.
On the same row, you'll also find the exact version number. Check in VisualStudio, whether the ASP.NET project uses the same one.
If I'm not mistaken, the main dependency of Oracle.DataAccess.dll is OraOps11w.dll, which should be available in the BIN directory of the Oracle client directory. This directory is usually located via the registry (HKLM\SOFTWARE\ORACLE\ODP.NET\<version>\DllPath). Make sure you look at the registry of the correct bitness (32 vs 64 bit).
There are more things that can go. But these here usually solve the problem.

Could not load assembly System.Data.SQLite.dll

I have a perfectly working windows forms C# .NET 4 application that uses a SQLite3 database file to store data and display forms.
When I deploy my app on any machine other then the dev machine, I get an exception thrown and it's message is "Could not load assembly System.Data.SQLite.dll or one of its dependencies. The specified module could not be found."
The System.Data.SQLite.dll reference in the project is set to Copy Local = True. Also, I tried manually loading the assembly with Assembly.LoadFile. The dll is placed in the output directory. I also tried setting the platform target to Any CPU as well as x86, no difference. All machines I am working with are 32-bit. What is the issue here? Why is my application trying to load the assembly and can't find it?
Thanks!
I had the same problem after publishing my program to a separate computer. Installing Microsoft Visual C++ 2010 Redistributable Package (x86) on the separate computer fixed the problem.
Note: the separate computer already had Microsoft Visual C++ 2010 Redistributable Package (x64) installed, the x86 version was needed.
'System.Data.SQLite.dll" requires "msvcr100.dll" which is one of it's Dependencies. This will be available only if you installed latest "Microsoft Visual C++ Redistributable" or any other product which internally provides this.
For example, VS2010 will install C++ Redistributable by default. Thats the reason your application doesnot works in some machine but works in others.
You could try pasting the "msvcr100.dll" in your application bin folder and distribute if you dont want to install VC++ 2010 Redist in all the PC's.
Some of the System.Data.Sqlite.dll modules depend on the "Microsoft Visual C++ 2012 Redistributable Package" .
You can find required dependencies on the official download page : http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
The answers already given didn't solve my problem. I tried to deploy to a VMware server. The solution that did help where given here: http://sqlite.1065341.n5.nabble.com/System-Data-SQLite-Deployment-Mystery-td71752.html Two methods are described there.
When i install this sqlite-netFx45-setup-bundle-x86-2012-1.0.88.0.exe, my app is able to find the right dll.
The second method is to add the dll to de app.exe.config in the debug or release dir. If you edit this file directly, there is a change VC will overwrite the file.
My main problem was that i installed the sqlite package manually. I didn't use NuGet, because i'm behind a proxy. If you do use Nuget, the information in the app.exe.config will be provided automatically.
Using NuGet behind a proxy is described here: NuGet Behind Proxy

How to Make ODP.NET 4.0 (64 bit) working on 64 bit machine Windows 7?

I am trying to run my ASP.NET 4.0 WebSite using the ODP.NET 4.0 Client in Windows 7 64 bit machine..but no luck so far.
I have downloaded the ODP.NET 4.0 from
http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html
and installed using the instructions provided.
I am able to see both the Oracle.DataAccess.dll and Oracle.Web.dll in
C:\Windows\Microsoft.NET\assembly\GAC_64\Oracle.DataAccess\v4.0_4.112.2.0__89b483f429c47342
and
C:\Windows\Microsoft.NET\assembly\GAC_64\Oracle.Web\v4.0_4.112.2.0__89b483f429c47342
respectively.
The problem is when I try to Add the reference to the website, I am not able to see them in GAC ( I mean to say in the .NET tab..where all the dlls in GAC are shown)
I somehow referenced them from my local system..
But after adding the reference the following entries are created in the web.config file.
And the problem is..
When I try to build the project it fails giving me an error stating that
Could not load file or assembly 'Oracle.DataAccess, Version=4.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified.
The reason I am thinking it is not finding the file is because it is looking in the GAC folder(C:Windows\Assembly) and as they are not present ..it is throwing the compile time error.
But technically the files must be located in the GAC64 folder(C:\Windows\Microsoft.NET\assembly\GAC_64\Oracle.DataAccess\v4.0_4.112.2.0__89b483f429c47342) and the dll is present there.
I don't know how to resolve this error.
Note: I have to run this in 64 bit machine and that too by setting the Enable 32 bit Applications flag to false in the IIS.
I would search your system for this library - generally it will exist somewhere else on your system before being added to the gac. Add the reference from that location - try: ORACLE_BASE\ORACLE_HOME\ASP.NET\Bin\2.x\ or c:\Oracle\odp.net\bin\2.x\Oracle.Web.dll
Whatever you see on that GAC reference tab is not in the gac jsut because it is on that tab. Those files are just 'reference assemblies' and can be anywhere on your system. Find the dll that is not in the GAC and add a reference to it from there. Search your system for oracle.web.dll
Note that in:
Oracle Providers for ASP.Net Installation
The location is listed as: c:\Oracle\odp.net\bin\2.x\Oracle.Web.dll

Resources