0

I have an Oracle(12g x64) database that I am trying to connect to using EF (6.x.x) data first approach in an MVC application. However I get a BadImageFormatException.

enter image description here

I am running everything x64. "Any CPU" is changed to x64. IIS AppPool "Allow 32-bit apps" is set set to false. Project Platform is set to x64 The same environment works fine with plain ADO.NET connections.

Has anyone successfully achieved this?

EDIT:

This link does not provide the answer. I am getting the error only when trying to connect through Server Explorer. Plus, I am using everything x64 to work with my other project. If I install another (x86) client and/or change paths of the current client and dlls it will mess up everything for the other project also. I have installed the Oracle.ManagedDataAccess and the Oracle.ManagedDataAccess.EntityFramework nuget packages in my MVC (current) Project. So it removes the requirement for a x86 client.

Community
  • 1
  • 1
who-aditya-nawandar
  • 1,334
  • 9
  • 39
  • 89
  • Possible duplicate of [BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed](http://stackoverflow.com/questions/24104210/badimageformatexception-this-will-occur-when-running-in-64-bit-mode-with-the-32) – atokpas Nov 22 '16 at 06:15
  • Clearly written that you are using 32 bit oracle client. Install 64 bit oracle client – Shariar Imtiaz Nov 22 '16 at 06:16
  • There's no 32-bit client installed on my computer. Like I said, I am using a x64 client. Even the data access assembly (that I am using in another webforms application) is coming from GAC_x64 folder. – who-aditya-nawandar Nov 22 '16 at 06:19
  • Visual Studio itself is a 32-bit application. If you like to debug your application you have to use the 32-bit Oracle Client. – Wernfried Domscheit Nov 22 '16 at 07:33
  • The error message does not match to ODP.NET Managed Driver, i.e. `Oracle.ManagedDataAccess`. Check carefully your references and namespaces in your project. – Wernfried Domscheit Nov 22 '16 at 07:34
  • What do you mean by "The same environment works fine with plain ADO.NET connections."? – Wernfried Domscheit Nov 22 '16 at 07:36
  • @Wernfried Domscheit: "If you like to debug your application you have to use the 32-bit Oracle Client." - Not necessarily. I have been using x64 Client and debugging my application all fine, setting the CPU in VS to x64. And Plain ADO.Net connections means when I am not using EntityFramework or not trying to make a connection via server explorer. – who-aditya-nawandar Nov 22 '16 at 07:41
  • Yes, you are right. But at least in version 2012 you cannot edit your code while debugging in 64-bit mode. – Wernfried Domscheit Nov 22 '16 at 07:56

1 Answers1

0

I will try to enumerate the steps.

From here: http://www.oracle.com/technetwork/topics/dotnet/downloads/index.html

  1. Download Entity Framework "Oracle Developer Tools for Visual Studio 2015 - MSI Installer" This will provide the EF tools. These tools are compiled in x86

  2. Download "64-bit ODAC Downloads" I would suggest the "64-bit ODAC 12c Release 4 (12.1.0.2.4) for Windows x64" wich has an installation wizard

  3. Use Nuget to install Oracle.ManagedDataAccess.EntityFramework nuget packages in your project

enter image description here

  1. Go to your web-->properties--> and set platform target to x64 in Release Mode

enter image description here

At this point, it should work properly in debug mode and release mode in your machine

  1. In the IIS server you should only install "64-bit ODAC 12c Release 4 (12.1.0.2.4) for Windows x64" and configure the tnsnames file

  2. Deploy all the contents of the bin\x64 folder to the IIS server. No further configuration in IIS if it´s an x64 operating system

Hope it helps

ssanga
  • 335
  • 3
  • 11