0
votes

I am new to .Net. I created a code which connects to database and performs some transaction. For Data Access Manager, I added reference Oracle.DataAccess.86 (Oracle.DataAccess.dll) and Run with "Any CPU" in local. It works fine. But when I deploy it on server which has 64 Bit IIS running, then it's giving me below 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. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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.

[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.] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +225 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +110 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22 System.Reflection.Assembly.Load(String assemblyString) +34 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

How can I find a solution for this error?

2
Check this question. It sounds like a likely solution... stackoverflow.com/questions/1707101/…Reinstate Monica Cellio
@WernfriedDomscheit All they have to do is set the AppPool to run as a 32 Bit app and it will rule that answer out, but they won't. They don't need ODP.Net installed if they have the prerequisite assemblies included in the project, but that's another question entirely. Until OP answers the questions posed and responds accordingly to suggestions made then everything is pure guesswork.Reinstate Monica Cellio

2 Answers

1
votes

Your problem is that wrong Oracle DLL being loaded into memory

If you build your assembly to AnyCPU...

Requirement to run as x64 - Oracle Client x64 installed, Oracle.DataAccess.dll x64 deployed, AppPool set "run 32 bit" = false.

Requirement to run as x86 - Oracle Client x86 installed, Oracle.DataAccess.dll x86 deployed, AppPool set "run 32 bit" = true.

BUT why would you use Oracle.DataAccess.dll in 2019? Use Oracle.ManagedDataAccess.dll. Install small set of connectivity components (ODAC) and no need for Oracle client, x64/x86 - all will be done as AnyCPU. Better yet, install Oracle Development tools for Visual Studio, which will include ODAC

0
votes

If the IIS is 64 bit, then you also need the 64-bit version of Oracle.DataAccess.dll. I assume the Oracle.DataAccess is not installed at all on your server, please verify correct installation. Note, Oracle.DataAccess.dll requires an Oracle Client (typically the Oracle Instance Client), this must also be the same architecture as the Oracle.DataAccess.dll.

The reference to Oracle.DataAccess.dll is the same. The application (IIS in your case) will load the correct assembly automatically - provided it is installed and available on the machine. You may remove the processorArchitecture=x86 attribute in your project file, you can edit the *.csproj, resp. *.vbproj file manually with a text editor.