Click here to Skip to main content
15,606,999 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have developed a C# application which uses Oracle.DataAccess to connect to an Oracle database. I have built it in x86 configuration and install it on the server machine (32 bit) and the program runs correctly.
When I try to run it from the client (64 bit) I obtain a "System.BadImageFormatException: unable to load file or assembly Oracle.DataAccess..." .
What could be reason of this error?
I have already tried to rebuild the solution in Any CPU, but I obtain the same exception.
Any help will be pleasant. Thanks in advance.
Updated 17-May-22 22:01pm

Your code is compiled to target AnyCPU, which will run as 32-bit on a 32-bit processor and 64-bit on a 64-bit processor.

The problem comes when you try to use 32-bit only components in your code. On a 32-bit machine, everything works fine. But when you try to run your code on a 64-bit machine, it's still trying to use a 32-bit component. You cannot mix 32- and 64-bit code in the same process.

The solution is usually easy. Recompile your app to target x86 only. Go into your project Properties, Compile or Build tab, and change the Platform Target to x86.
Share this answer
That exception happened to me as well but with SQL Server and another dll. Solution was to find and deploy the 64bit of the dll involved. So try to see if a 64bit build exists for Oracle.DataAccess and reference that in your app which of course you'll have to compile one for x86 and one for x64
Share this answer
please also note that the version of "WebView2Loader.dll" which is in use is very crucial. I had almost the same problem with "Microsoft.WebView2.FixedVersionRuntime.101.0.1210.39.x64" when I tried to use the WebView2 component in the MMC Snap-Ins with types of "HTMLView" or "FormView".
I just copied the abovementioned dll file (version 1.0.1248.0, size=157640 bytes) in a proper path that was accessible for the project (you could just put it beside your project output files first to test it) and then WebView2 browser started to function as expected. Microsoft error messages sometimes (at least in my case) was a little bit misleading and did not convey enough and to the point information. 
I received "BadImageFormatException" that normally occurs when you mix platform targets (for example using a dll file compiled in X64 in an application that targeted for x86 or vice versa) or mix native code and .NET but that was not my problem at all. I hope this help one who may stuck in.
Share this answer
Richard Deeming 18-May-22 4:51am    
This question was solved nine years ago. It made no mention of WebView2. And assuming this is the Microsoft WebView2 control, that wasn't released until October last year, so there's no way it could be relevant to the question.

Which means your new solution is simply a repeat of the accepted solution: that you can't use a 64-bit dll from a 32-bit process, and vice-versa.

Unless you're going to add something new to the discussion, stick to answering newer questions where the poster still needs help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900