0

I am running:

  1. Windows 10 Home
  2. Oracle Database 11g Enterprise Edition 11.2.0.1 - 64 bit version
  3. Visual Studio Express 2013

I want to write a simple C# application to read data from the Oracle database and want to use ODP.NET. However, when running the program I'm getting an immediate Runtime Error.

  1. I started a new Windows Forms project.

  2. I linked service Oracle.DataAccess.dll in directory c:\app\Dave\product\11.2.0\dbhome_1\ODP.NET\bin\2.x\

My code is:

using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace testapp_2
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Code :

using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;  

namespace testapp_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            OracleConnection conn = new OracleConnection();
        }
    }
}

The error is:

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

When running in debug mode, the program halts at line:

Application.Run(new Form1());

I have used this in the past successfully with Visual Stdio Express 2008 and Oracle 10g under Windows XP and thought this would be very simple just like before, but apparently not.

Has anyone else encountered this error and hopefully have found a workaround for it? I would be most appreciative of any help or information.

Thank you very much!

-Dave.

toha
  • 4,097
  • 3
  • 31
  • 49

2 Answers2

0

In some cases where .net DLL is not targeting both x86 and x64 platform (like Microsoft Expression Encoder) under 64-bit system. this error might occur when launching debugging (not sure it's the same case for ODP.NET). The solution is to change your build settings in the project to target x86 instead of Any CPU.

Ge Rong
  • 386
  • 4
  • 15
0

Thanks to everyone for posting so many helpful comments.

I tried following the suggestion to change the target CPU to x86 instead of Any CPU (I also tried x64), but it made no difference.

But thinking about that topic got me thinking that perhaps this is an old ODP.NET dll, and isn't compatible with the current/latest versions of .NET.

So (in Properties and the Application tab, I changed the target .NET framework to be .NET 3.5 and sure enough that solved my problems!

I'm now able to read and write data to and from the database from C#! I'm very happy and relieved that it is now working.

Thanks again to everyone for their assistance in leading me to solving this issue! :-)

-D.