Could not load file or assembly 'Oracle.DataAccess error - c#

I am building ASP.NET application with C# and I want to connect to oracle database.
I have added reference to Oracle.DataAccess in my application on my 64bit Microsoft Window Server 2008 machine.
I also installed ODAC (Oracle Data Access Component) on my machine
and Oracle.DataAccess.dll is also present on this path
C:\Windows\Microsoft.NET\assembly\GAC_64\Oracle.DataAccess
but when i'm trying to connect i encounter following error:
Could not load file or assembly 'Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified.

As far as I know, the Oracle.DataAccess assembly works only with 32 bits, I also have this kind of problem with 64 bits and it really does not work. My solution was remove the 64bits from GAC and install the 32 bits on GAC. I also remove any .dll file in the bin folder to my application find the assembly on GAC.
There is no problem if your machine and operational system is 64bits, the 32bits version will work fine.
UPDATE
I recommend you take a look at Official Oracle ODP.NET, Managed Driver, that is a better version than Oracle.DataAccess. This Managed Driver does not need the Oracle Client on the machine, and you just need to provide the TNS on the DataSource field of the connection string and it works fine for 32 and 64 bits.

You need to install both x64 and x86 versions of Oracle, because something (I think it was Visual Studio) uses the x86 version when debugging.

In VS2010, I changed the platform target to x64 and this error message disappear.

essentially same error
missing ODP.NET installation components as per last post from me and the other answer participant.
You check the GAC yet?
If you do not see Oracle.xxx folders,
you are not making any headway.
put the correct version and bit of Oracle.DataAccess.dll into the application /BIN folder and make local reference. It solves many problems.

To run your website, you must use IIS since visual studio's development server only runs in 32 bit mode.
In IIS application pool, set your application to run in 64 bit. (The setting is in advanced settings)

To resolve this error, I set my app pool in IIS to allow 32bit applications.
Open up IIS Manager, right click on the app pool, and select Advanced Settings --> set “Enable 32-bit Applications” to True. It's working fine for me.

I got the same exception on a c# console app. What solved it for me is to change the platform target to x86. (project properties => build )

Related

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

I get the "Could not load file or assembly xxx or one of its dependencies*********" error when I host my website on a Windows Server 2012 (IIS 8). The xxx here is my project name in my local VS 2015. The application is working perfectly fine in my local PC
It is a VB.NET application with Oracle 12c database as it's backend.
Things I have tried till now.
1. Publish with setting the Target CPU as "Any CPU" and Configuration as "Release-Any CPU" - Still the same error.
2. In the Server IIS, I have set the Enable 32-but apps as True on App's App pool. This is giving a different 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.
Please help.
It sounds like your Oracle.DataAccess dll is a 64 bit dll. You can see what driver is loaded on the web server by navigating in Windows Explorer to the \windows\assembly folder.
Most applications that are built with the Any CPU option will have the checkbox in the project settings to prefer 32 bit. To avoid this, change your project's platform target to be a 64 bit.
Then you do not need to "Enable 32 bit" in your application pool and your problem should disappear. Please let me know if this helps.

System.Data.SQLite.dll - System.IO.FileNotFoundException

I use SQLite and works fine on the developer machine (or machine with Visual Studio).
But it does not work on PCs without VS. I "installed" the SQLite manually (32 bit version, added to the references, Copy Local: True). I get "System.IO.FileNotFoundException" System.Data.SQLite.dll exception.
The System.Data.SQLite.dll is in the output folder.
But I can not get it to work only if I install the SQLite with this: https://system.data.sqlite.org/downloads/1.0.105.2/sqlite-netFx46-setup-bundle-x86-2015-1.0.105.2.exe
Dev PC: x64 Win 10, application: x86 only
Please let me know if you need any other information.
Check which dependencies has your executable file (and, maybe, System.Data.SQLite.dll) with Dependency Walker or similar program. Then put these libraries you found into executable's folder one by one, until your executable will work.
You need to make sure the 64 bit C++ runtime DLLs are getting installed. They'll often be on the developer's system but not as often installed by your installer on the target system. Even though this is a .NET assembly, it appears to have C++ underpinnings.

"Cannot find assembly" error in VS 2008

I had a web service on a 32-bit WIndows 2003 server that accessed Oracle database. It was built and converted to DLL with no issues. Then I had to port this to Windows 2012 64-bit server and I keep getting
Could Not Load File Or Assembly 'Oracle.DataAccess' Or One Of Its Dependencies.
I downloaded and installed 64 bit ODAC, but the problem remained. It was suggested to install the 32 bit version as well and I did that, so now I have two directories in C, C:\Oracle\Products\11.2.0\client_1 and client_2, one for 64-bit and one for 32-bit. GAC also contains both x86 and AMD64 versions of Oracle.DataAccess and Oracle.Web. I still get the same error.
Looking closely, I found that when I close the error window in VS 2008, there is an output window that shows
Warning: Unable to update auto-refresh reference 'oracle.dataaccess.dll'. Cannot find assembly 'C:\Windows\Microsoft.NET\assembly\GAC_32\Oracle.DataAccess\v4.0_4.112.2.0__89b483f429c47342\oracle.dataaccess.dll'.
I checked and this folder is empty but there is a newer folder C:\Windows\Microsoft.NET\assembly\GAC_32\Oracle.DataAccess\v4.0_4.112.**3**.0__89b483f429c47342 with oracle.dataaccess.dll in it.
How can I resolve this issue? I don't know how to make the reference to v4.0_4.112.3.0__89b483f429c47342 folder instead of v4.0_4.112.2.0__89b483f429c47342 folder, if this is the cause of the problem.
I had a copy of DataAccess.DLL in BIN folder. I removed it and all is well.

ClickOnce: BadImageFormatException when running x86 package on 64 bit windows

My .NET 2.0 application imports unmanaged 32 bit dll.
The dll is loaded (first interop call happens) when user opens a file via a dialog within the application.
When I deploy the application via clickonce with target platform "Any", users on 64 bit windows get BadImageFormatException when trying to open files from the application (at the moment the unmanaged dll is loaded). I understand this is due to incompabible bitness of the 64 bit process and the 32 bit unmanaged dll.
I have redeployed the application using x86 as target platform. As I understand it, this should solve the bitness problem.
BUT
When I run the deployed application built for x86 on 64 bit system, I now get BadImageFormatException immediately before the application even starts. Tested on at least three 64 bit machines. On 32 bit machines, it works with no problem.
When I run the application directly from VS (or not directly, just a normal build, not going via ClickOnce), there is no problem on 64 bit windows when using x86 target platform. The application starts and user can load file - the interop call succeeds.
I have been debugging this for 2 days straight with no result - I have tried on different computers. It seems to consistentnly work on one of the computers I have tried. However, I do not have permanent access to this computer.
I have managed to build the ClickOnce deployment on my computer once and it worked on a 64 bit machine. This was single of maybe 100 tries! Nothing has changed, the only changed variable was that I did the successful build immediately after computer restart.
I did clean/rebuild/restart VS/restart windows MANY times. I have reinstalled VS 2008 and now also the whole OS, it did not help.
EDIT: I have just managed to get one good build (out of next 100 :)) and did comparison between the deployed directories.
The source of the problem is that ClickOnce generates the wrong target platform in the manifest of the main .exe:
<asmv1:assemblyIdentity name="app.exe" version="1.0.4.18" publicKeyToken=".token here." language="neutral" processorArchitecture="<b>msil</b>" type="win32" />
processorArchitecture should be x86.
So the question is how to consistently force VS to generate the correct processorArchitecture in the manifest when deploying.
Can anyone help please?
This was resolved by installing VS 2008 SP1 on 64 bit Windows 7. VS2008 SP1 on XP had the problem on two machines I have tried with.
I had this problem as well, using VS2008 SP1.
In my case I had a 32 bit DLL which had to be compiled as 32 bit and an application that was using it in the same solution.
Even though I specified X86 as the build target for the release build, when I published a 64bit application was compiled and included in the installer.
I found a slightly brutal solution to the problem:
Go into the configuration manager and remove all possible configurations except the one that you want it to build (Debug and release versions).
After doing this I found that the clickonce installer was generated with the correct application.
I hope this helps someone else, I have been battling this problem on and off for months.
I'd suggest to use Reflector to open the main exe deployed by ClickOnce and see the dependencies to make sure you are not deploying the 64 bit version of the dll by mistake.
You must resolve to run 32-Bit Applications in IIS 7. See http://www.fishofprey.com/2009/04/badimageformatexception-in-iis-70-on-64.html
Sometimes the ClickOnce publishing process seems to cache old files from previous Any CPU or x64 builds. Doing a Clean and Rebuild All didn't fix this problem for me. I needed to delete all of the bin and obj folders from my projects and reopen Visual Studio.
We ran into this problem and determined that the subdirectory of the user profile to which ClickOnce deployed our application must have become corrupted, because we were able to deploy the application successfully with ClickOnce when logged in as a different user on the same machine.
We were able to solve the problem simply by deleting the subdirectory of C:\Users\<user>\AppData\Local\Apps under which ClickOnce was deploying our application. In our case, this was C:\Users\<user>\AppData\Local\Apps\2.0.

I get a "An attempt was made to load a program with an incorrect format" error on a SQL Server replication project

The exact error is as follows
Could not load file or assembly 'Microsoft.SqlServer.Replication,
Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
or one of its dependencies. An attempt was made to load a program with
an incorrect format.
I've recently started working on this project again after a two month move to another project. It worked perfectly before, and I've double checked all the references.
The answer by baldy below is correct, but you may also need to enable 32-bit applications in your AppPool.
Source: http://www.alexjamesbrown.com/uncategorized/could-not-load-file-or-assembly-chilkatdotnet2-or-one-of-its-dependencies-an-attempt-was-made-to-load-a-program-with-an-incorrect-format/
Whilst setting up an application to run on my local machine (running Vista 64bit) I encountered this error:
Could not load file or assembly ChilkatDotNet2 or one of its
dependencies. An attempt was made to load a program with an incorrect
format.
Obviously, the application uses ChilKat components, but it would seem that the version we are using, is only the 32bit version.
To resolve this error, I set my app pool in IIS to allow 32bit applications.
Open up IIS Manager, right click on the app pool, and select Advanced Settings (See below)
Then set "Enable 32-bit Applications" to True.
All done!
I've found the solution. I've recently upgraded my machine to Windows 2008 Server 64-bit. The SqlServer.Replication namespace was written for 32-bit platforms. All I needed to do to get it running again was to set the Target Platform in the Project Build Properties to X86.
Change the value for Platform Target on your web project's property page to Any CPU.
Go to IIS
-> Application Pool -> Advance Settings -> Enable 32-bit Applications
We recently had the issue when trying to run the code from Visual Studio. In that case you need to do
TOOLS > OPTIONS > Projects and Solutions > WEB PROJECTS and check the "Use the 64 bit version of IIS Express for web sites and projects".
For those who get this error in an ASP.NET MVC 3 project, within Visual Studio itself:
In an ASP.NET MVC 3 app I'm working on, I tried adding a reference to Microsoft.SqlServer.BatchParser to a project to resolve a problem where it was missing on a deployment server. (Our app uses SMO; the correct fix was to install SQL Server Native Client and a couple other things on the deployment server.)
Even after I removed the reference to BatchParser, I kept getting the "An attempt was made..." error, referencing the BatchParser DLL, on every ASP.NET MVC 3 page I opened, and that error was followed by dozens of page parsing errors.
If this happens to you, do a file search and see if the DLL is still in one of your project's \bin folders. Even if you do a rebuild, Visual Studio doesn't necessarily clear out everything in all your \bin folders. When I deleted the DLL from the bin and built again, the error went away.
I had this in an MVC5 app in Windows 10 against IIS Express. My solution was the following:
Tools =>
Options =>
Projects and Solutions =>
Web Projects =>
Use the 64 bit version of IIS Express for web sites and projects
change it to 32-bit (true) it works
if you get this Length cannot be less than zero. Parameter name: length issue in iis server configuation do the simple thing change the connection string in web.config file like your sql server name and server name and restart iis then try to load the page it works
If Publishing in Visual Studio 2012 when erroring try unchecking the "Procompile during publishing" option in the Publish wizard.
in windows form application I do this,
Right-click on Project->Properties->Build->Check Prefer 32-bit checkbox.
Thanks all
Delete the temp test directory located here
C:\Users(User)\AppData\Local\Temp\VisualStudioTestExplorerExtensions\
Set all projects to x64 in Visual Studio
Set the default processor architecture to x64(Test/TestSettings/Default Processor Architecture).
Make sure to clean build the solution file.Hope this helps!
Changing the Target Framework in project properties from .NET Framework 4.7.1 to 4.6.2 worked for me.

Categories