Search code examples
c#.netoracleodp.netdata-access

Getting missing dependency error for 'Oracle.DataAccess' when deploying on IIS 64 Bit Server


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?


Solution

  • 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