0

I'm working on a C# project in Visual Studio 2012 on Windows 10 and Oracle 11g. In order to connect my c# project I had to install Oracle Data Access Components_ODTwithODAC121024 and everything worked fine.

I updated the target .NET framework of my project to 3.5, and now I get this error:

Could not load file or assembly 'Oracle.DataAccess, Version=2.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format.

After really long search and test I think that caused by incompatibility issue. I tried to enable .NET Framework 3.5 through Programs and Features -> Turn Windows features on or off.

I tried to read reference and importing the Oracle.DataAccess.dll from

C:\app\Samer\product\11.2.0\dbhome_1\ODP.NET\bin\2.x

and I also used the Oracle.DataAccess.dll that comes with Oracle Data Access Components

My project works fine when I disable the method that deals with oracle commands.

Here is the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Oracle.DataAccess;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

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

        Read_const_File();
    }

    //Method for Reading Constants File
    public void Read_const_File()
    {
        string File_Path;
        File_Path = @"s:\test\result";
        Get_File_info(File_Path);
    }

    //Method for reading file information ex(File Name,Size,and creation date..etc)
    public void Get_File_info(string para1)
    { 
        FileInfo info = new FileInfo(para1);
        richTextBox1.AppendText(Environment.NewLine + "File Name: " + Path.GetFileNameWithoutExtension(info.Name));
        richTextBox1.AppendText(Environment.NewLine + "File Size (Bytes): " + info.Length.ToString());
        richTextBox1.AppendText(Environment.NewLine + "Creation Time: " + info.CreationTime.ToString());
        richTextBox1.AppendText(Environment.NewLine + "Last Access: " + info.LastAccessTime.ToString());
        richTextBox1.AppendText(Environment.NewLine + " **************************** ");

        search_for_string(para1);
    }

    public void search_for_string(string para2)
    {
        string keywords = "sb_0501_Thu.dmp";
        string oradb = "Data Source=sb_1901;User Id=sb_1901;Password=sb00;";

        StreamReader sr = new StreamReader(para2);
        richTextBox1.AppendText(Environment.NewLine + sr.ReadToEnd());

        if (!richTextBox1.Text.Contains(keywords))
        {
            OracleConnection conn = new OracleConnection(oradb);
            conn.Open();

            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = "insert into backup_check(REC_ID,OFFICE_CODE,DUMP_NAME,DUMP_STATUS,SYSTEM,CHECK_DATE)values(null,null,'keywords',0,'SBank',sysdate)";
            int rowsupdated = cmd.ExecuteNonQuery();
            if (rowsupdated == 0)
            { MessageBox.Show("NONE"); }
            else
            { MessageBox.Show("Done"); }

            conn.Dispose();
        }
        else
        {
            OracleConnection conn = new OracleConnection(oradb);
            conn.Open();

            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = "insert into backup_check(REC_ID,OFFICE_CODE,DUMP_NAME,DUMP_STATUS,SYSTEM,CHECK_DATE)values(null,null,'keywords',1,'SBank',sysdate)";
            int rowsupdated = cmd.ExecuteNonQuery();
            if (rowsupdated == 0)
            { MessageBox.Show("NONE"); }
            else
            { MessageBox.Show("Done"); }
            conn.Dispose();
        }
    }
}

}

CHendrix
  • 318
  • 2
  • 12
samer
  • 183
  • 3
  • 21

1 Answers1

0

You refer to ODP.NET version 2.121.2.0. but it seems you have installed Oracle Client 11.2. The versions have to match with each other (at least the major version number)

Open your *.csproj file and set reference of Oracle.DataAccess like this:

<Reference Include="Oracle.DataAccess">
  <SpecificVersion>False</SpecificVersion>
</Reference>

Attributes like Version=... or processorArchitecture=... are not required. Your application will load the correct Oracle.DataAccess.dll depending on selected architecture and target .NET framework

Wernfried Domscheit
  • 38,841
  • 5
  • 50
  • 81
  • There was a mismatch between the processor architecture of the project being built MSIL and the processor architecture of the reference Oracle.DataAccess Version=2.112.3.0 Culture=neutral PublicKeyToken=89b483f429c47342 processorArchitecture=x86""x86" This mismatch may..... – samer Feb 26 '16 at 15:28
  • cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project – samer Feb 26 '16 at 15:28
  • yes and I tried every possible way to avoid that mismatch but I fail please lead me to away to avoid this mismatch I had download and install the Oracle Data Access Components 11 and imported form C:\app\Samer\product\11.2.0\dbhome_1\ODP.NET\bin\2.x\Oracle.DataAccess.dll – samer Feb 26 '16 at 15:33
  • after ur suggestion and installing the Oracle Data Access Components the problem not solved – samer Feb 26 '16 at 15:42
  • Check also this answer: http://stackoverflow.com/questions/659341/the-provider-is-not-compatible-with-the-version-of-oracle-client#25412992 – Wernfried Domscheit Feb 27 '16 at 18:07