6 Replies Latest reply on May 3, 2014 4:25 PM by Alex Keh - Product Manager-Oracle

    Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies

    Maahjoor

      Dear all,

       

      The configuration related to my problem are below;

       

      1. Microsoft Windows 8 64 bits
      2. Microsoft Visual Studio Professional 2013
      3. DOT.Net framework 4.5
      4. Oracle Database 12c Release 12.1.0.1.0
      5. ODTwithODAC121012 (32bit) ---- i think problem is here, but there is no 64 bit odac which provide odp for vs2013.
      6. Microsoft Internet Explorer 10
      7. Latest version of IIS

       

      i have created a simple application with Grid View control like below;

       

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using Oracle.DataAccess.Client;
      using Oracle.DataAccess.Types;
      using System.Data;
      using System.Configuration;
      namespace WebApplication18
      {
          public partial class WebForm1 : System.Web.UI.Page
          {
              protected void Page_Load(object sender, EventArgs e)
              {
                  string oradb = "Data Source=pdborcl;User Id=PAKICON;Password=pakicon;";
                  OracleConnection conn = new OracleConnection(oradb);
                         string sql = "select * from user_accounts";
                  OracleCommand cmd = new OracleCommand(sql, conn);
                  cmd.CommandType = CommandType.Text;
                  cmd.Connection = conn;
                  cmd.CommandText=sql;
                  OracleDataAdapter da = new OracleDataAdapter();
                  da.SelectCommand = cmd;
                  DataSet ds = new DataSet();
            
                       conn.Open();
                  cmd.ExecuteNonQuery();
                  da.Fill(ds);
                  conn.Close();
                  GridView1.DataSource=ds;
                  GridView1.DataBind();
                      }
          }
      }
      

       

      when i try to run it, i receive this error on internet explorer page

       

      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.


      Assembly Load Trace: The following information can be helpful to determine why the assembly 'Oracle.DataAccess' could not be loaded.

      === Pre-bind state information ===

      LOG: DisplayName = Oracle.DataAccess

      (Partial)

      WRN: Partial binding information was supplied for an assembly:

      WRN: Assembly Name: Oracle.DataAccess | Domain ID: 2

      WRN: A partial bind occurs when only part of the assembly display name is provided.

      WRN: This might result in the binder loading an incorrect assembly.

      WRN: It is recommended to provide a fully specified textual identity for the assembly,

      WRN: that consists of the simple name, version, culture, and public key token.

      WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.

      LOG: Appbase = file:///c:/users/administrator/documents/visual studio 2013/Projects/WebApplication18/WebApplication18/

      LOG: Initial PrivatePath = c:\users\administrator\documents\visual studio 2013\Projects\WebApplication18\WebApplication18\bin

      Calling assembly : (Unknown).

      ===

      LOG: This bind starts in default load context.

      LOG: Using application configuration file: c:\users\administrator\documents\visual studio 2013\Projects\WebApplication18\WebApplication18\web.config

      LOG: Using host configuration file: C:\Users\Administrator\Documents\IISExpress\config\aspnet.config

      LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.

      LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).

      LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/4e39ee31/273a2d26/Oracle.DataAccess.DLL.

      LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/4e39ee31/273a2d26/Oracle.DataAccess/Oracle.DataAccess.DLL.

      LOG: Attempting download of new URL file:///c:/users/administrator/documents/visual studio 2013/Projects/WebApplication18/WebApplication18/bin/Oracle.DataAccess.DLL.

      ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

       

      Stack Trace:

       

      [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.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34

        System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152

        System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77

        System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16

        System.Reflection.Assembly.Load(String assemblyString) +28

        System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

       

      [ConfigurationErrorsException: 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.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752

        System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218

        System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130

        System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170

        System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91

        System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +285

        System.Web.Compilation.BuildManager.ExecutePreAppStart() +153

        System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

       

      [HttpException (0x80004005): 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.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9915300

        System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101

        System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

       

      Kindly guide me since i have searched a lot and practice, but failed.

       

      thank you.

        • 1. Re: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies
          Alex Keh - Product Manager-Oracle

          There exists no 64-bit software for Visual Studio because VS is a 32-bit app. And you can't load 64-bit libraries into a 32-bit executable.

           

          When you run ODP.NET (or any ADO.NET provider), it's actually running within the .NET Framework, not VS. If you want to run 64-bit ADO.NET, then you use 64-bit .NET Framework within Visual Studio. If you want to run 32-bit ADO.NET, you use 32-bit .NET Framework.

           

          Download 64-bit ODP.NET and use that in your project.

           

          Visual Studio can continue to use 32-bit ODT and ODAC.

          • 2. Re: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies
            Maahjoor

            thank you,

            but i am still facing the same problem.

            i have done the following practices.

             

            1. i assume that my dot net framework is 32 bit because the folder ".NETFramework" is only in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework

            and not in C:\Program Files\Reference Assemblies\Microsoft\Framework.

             

            2. i download the ODTwithODAC121012 32bit version and install it.

             

            3. i have change the PLATFORM TARGET from the properties of the solution explorer to 86 architechture and try the application but in vain.

             

            4. i have try to change the property of the dot net frameworks in the IIS using inetmgr and then under application pools there are dot net frame works.

            i allow the ENABLE 32 BIT OPERATION from there for each dot net frame work.

             

            but i am still facing the same error for the code i mention in my first post.

            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.
            

            kindly give me some clue.. the problem is i am very new to visual studio.


            thank you.

            • 3. Re: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies
              Maahjoor

              one more thing, the problem is with the follwoing line because the VS is pointing to it.

               

              conn.open():

              • 4. Re: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies
                Alex Keh - Product Manager-Oracle

                The error you see indicates that you have both a 32-bit and 64-bit Oracle Client on your machine. Assuming you're loading the 32-bit ODP.NET version, it's trying to load 64-bit Oracle Client dependent DLLs when it should be trying to load 32-bit ones.

                 

                Set the ODP.NET configuration setting DllPath in your .NET config file to point to the Oracle bin directory for where it should find its dependent DLLs. That should resolve the problem. Chapter 2 of the ODP.NET doc will describe how to use DllPath.

                • 5. Re: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies
                  Maahjoor

                  Thanks,

                   

                  i remove both the xcopy and odac 32 bti with visual studio from my system, and re-install ODAC 32bit with visual studio.

                  in my web.config file, i do the following entry under the configuration tag

                   

                  <oracle.dataaccess.client>
                      <settings>
                        <add name="DllPath"               value="C:\app\Administrator\product\11.2.0\dbhome_2\bin"/>
                        <add name="FetchSize"             value="65536"/>
                        <add name="PromotableTransaction" value="promotable"/>
                        <add name="StatementCacheSize"    value="10"/>
                        <add name="TraceFileName"         value="C:\odpnet2.trc"/>
                        <add name="TraceLevel"            value="63"/>
                        <add name="TraceOption"           value="1"/>
                      </settings>
                    </oracle.dataaccess.client>
                  

                   

                  i have write a very simple code to just check whether it is opening the connection or not

                   

                  using System;
                  using System.Collections.Generic;
                  using System.Linq;
                  using System.Web;
                  using System.Web.UI;
                  using System.Web.UI.WebControls;
                  using Oracle.DataAccess.Client;
                  using Oracle.DataAccess.Types;
                  using System.Data;
                  using System.Configuration;
                  using System;
                  using System.Drawing;
                  using System.ComponentModel;
                  using System.Windows.Forms;
                  namespace WebApplication23
                  {
                      public partial class WebForm1 : System.Web.UI.Page
                      {
                          protected void Page_Load(object sender, EventArgs e)
                          {
                        OracleConnection conn = new OracleConnection();
                  conn.ConnectionString = "Data Source=NEWDB;User ID=SYSTEM;Password=admin";
                  try
                  {
                  conn.Open();
                  conn.Close();
                  MessageBox.Show("Connection successful!");
                  }
                  catch (Exception ex)
                  {
                      MessageBox.Show(ex.ToString(), "Error connecting to Oracle");
                  }
                  }
                          }
                      }
                  

                   

                  in the message box after i run it, it give the following error

                   

                  Oracle.DataAccess.Client.OracleException at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode,
                  OracleConnection connn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck int32 isRecoverable)
                  at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode,
                  OracleConnection conn, IntPtr opsErrCtx, Object src)
                  at Oracle.DataAccess.Client.OracleConnection.Open() 
                  at WebApplicaiton23.WebForm1.page_load(Object sender, EventArgs e) in
                  C:\users\Administrator\Documents\Visual Studio 2013\Projects\WebApplication23\WebApplication23\WebForm1.aspx.css:line 25
                  

                   

                  below is DBproiderFactories entry from my C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config file.

                  <system.data>
                      <DbProviderFactories>
                        <add name="ODP.NET, Unmanaged Driver" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET, Unmanaged Driver" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
                        <add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
                        <add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
                        <add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
                        <add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
                        <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
                      </DbProviderFactories>
                    </system.data>
                  
                  • 6. Re: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies
                    Alex Keh - Product Manager-Oracle

                    When you catch the exception, can you find out what the error number and text is? If there's an inner exception, that info would also be useful. The OracleException object has APIs to pull this info out or you can just run it in VS and examine the exception object.

                     

                    Another thing you can try is using Server Explorer to create a DB connection to Oracle. You should see similar error information there as well.