0

I am beginner developing in .NET I already installed the references in my project, which are described below.

  • Oracle.DataAccess
  • System.Data.OracleClient

Code is this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Oracle.DataAccess.Client; // ODP.NET Oracle managed provider
using Oracle.DataAccess.Types;

namespace testingconnection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //string oradb = "Data Source=ORCL;User Id=hr;Password=hr;";
            string oradb = "DATA SOURCE=BLANK;USER ID=USER;Password=password";
            OracleConnection conn = new OracleConnection(oradb);  // C#
            conn.Open();
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = "select DESCRIPTION from ncr where ncr_no ='60'";
            cmd.CommandType = CommandType.Text;
            OracleDataReader dr = cmd.ExecuteReader();
            dr.Read();
            label1.Text = dr.GetString(0);
            conn.Dispose();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}

The errors is:

  • $exception {"Could not load file or assembly 'Oracle.DataAccess, Version=2.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format."} System.BadImageFormatException o

More details

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************

System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess, Version=2.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'Oracle.DataAccess, Version=2.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342'
   at testingconnection.Form1.button1_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].



************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.3416.0 built by: NET472REL1LAST_B
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
testingconnection
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/jlsanche/source/repos/testingconnection/testingconnection/bin/Debug/testingconnection.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.3324.0 built by: NET472REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.3451.0 built by: NET472REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.3221.0 built by: NET472REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.3324.0 built by: NET472REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.3429.0 built by: NET472REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.3221.0 built by: NET472REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
JUANLUISSG
  • 63
  • 1
  • 8
  • There are several SO questions for this issue already, could [this](https://stackoverflow.com/questions/29332898/could-not-load-file-or-assembly-oracle-dataaccess-version-4-112-4-0-culture-n) be of any help. You should set your projects [target platform](https://rambletech.wordpress.com/2011/09/26/could-not-load-file-or-assembly-oracle-dataaccess-error/) and give it a try – Simon Wilson Mar 04 '20 at 18:23
  • 1
    BadImageFormatException is usually related to 32bit vs 64bit. You should use the [Oracle Managed Driver](https://www.nuget.org/packages/Oracle.ManagedDataAccess/) which is written in pure .NET and thus has no difference for 32bit vs 64 bit. – mason Mar 04 '20 at 18:32
  • Have a look at this: https://stackoverflow.com/questions/659341/the-provider-is-not-compatible-with-the-version-of-oracle-client#25412992 - The error message is different but it is the same problem. – Wernfried Domscheit Mar 04 '20 at 18:46
  • Apparently you use .NET Framework version 4.7, however you installed `Oracle.DataAccess` Version 2.x - this does not match. Install version 4.x or change your compiler settings and target .NET Framework version 2 – Wernfried Domscheit Mar 04 '20 at 19:08

2 Answers2

0

I had a similar problem to this where the package was calling 64 bit dependencies while my program was for 32. I can't really see what is the EXACT DataAccess package you have but the problem I had was that Orcale gives the same rev number to the packages of 32 and 64 so I got the wrong mix of the files, What I had to do back then is to 1. Uninstall the DataAcess package I had. 2. Instal the Orcale dataAcess 32-bit from the Orcale websit as the 64-bit one still has the same rev number which was confusing. From here

-2

The error message is that Visual Studio cannot find the Oracle dll. It can be very frustrating so try these basic checks

  • Check that your references are to the same version number you installed. Unlikely but still possible
  • Verify the oracle dll is located in your bin folder. Again, unlikely but possible
  • verify the oracle dll in your global assembly cache or copy it there see here
  • if that doesn't work try setting the dll project properties to "Copy Local" see here. Then rebuild your project and verify the dll is in the bin folder
kevinskio
  • 4,431
  • 1
  • 22
  • 36
  • When a DLL is stored in Global Assembly Cache then this takes precedence over the file located in your bin folder. The GAC also takes care about different versions and redirecting. – Wernfried Domscheit Mar 04 '20 at 19:12
  • @WernfriedDomscheit Agreed, that's what is supposed to happen. But when you're developing and updating your build can get out of sync and give you errors like the OP – kevinskio Mar 04 '20 at 19:36