9

I am trying to run a .NET application which uses System.Data.OracleClient on a Win7 x64 workstation. The workstation has a 32bit Oracle client installed, which leads to the following error message:

Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.

So this is my long journey of tries and failures:

  1. I tried to install the Oracle client win64_11gR2_client. But during the setup process it crashes without any comment.
  2. I followed an answer from a different SO thread, tried and extracted the instantclient-basic-windows.x64-11.2.0.2.0, and put the folder containing the binaries in the windows PATH variable. I still get the same error message though (even after rebooting).
  3. I followed the "alternative way" from this answer and copied the files oci.dll, orannzsbb11.dll, and oraociei11.dll into the bin/ folder of my web site project. Still the same error message.
  4. I tried and copied all files from the instant client into that directory and tried again, without success.
  5. I installed ODAC112021Xcopy_x64.zip and put the installation folder and the bin folder in the windows PATH variable. No success.
  6. I put my hope on this answer and reviewed the DllPath in the registry (which is actually supposed to relate to ODP.NET as opposed to System.Data.OracleClient) and saw that DllPath points to the correct x64 installation of ODAC, so, if my application wasn't using System.Data.OracleClient, it should work,b but since it does use that, it still failed.
  7. I googled and stackoverflew but didn't find anything else that the posts I already referred to.
  8. I carefully crafted this SO question in the hope of getting any insightful advice from an enlightened SO user.
  9. After getting the first answer from b_levitt, I tried and added the following lines to the Global.asax at Application_Start:

    Environment.SetEnvironmentVariable("ORACLE_HOME", @"C:\OracleProducts\Odac-11.2.0.2.1-x64");
    Environment.SetEnvironmentVariable("PATH", @"C:\OracleProducts\Odac-11.2.0.2.1-x64;C:\OracleProducts\Odac-11.2.0.2.1-x64\bin");
    

    C:\OracleProducts\Odac-11.2.0.2.1-x64 is where I installed the ODAC 64 bit xcopy version. No success either.

On a related note, I even tried to force my .NET app into 32bit mode without success, but that's a different thing. I need a forward-looking solution, which means 64bit.

2 Answers 2

4

Your #5 should have worked but you also need to set the ORACLE_HOME environment variable. I've done this many times including recently with the very xcopy install that you are using. Please check out my experience with the xcopy install and let me know what kind of additional errors that you get.

In my case I was setting it up for asp.net, but winforms is even easier. You can open a cmd window, use the "set" command to set both the PATH and the ORACLE_HOME environment variables and then run your app from that same cmd window. Once you get the bugs worked out, you can use the Environment.SetEnvironmentVariable to set these within your code.

For the record, I do avoid installing the oracle client on client machines by handling all of the business logic via web services. That way I only need the oracle components on the web server.

5
  • This looks promising. Will have a try when back to work. In fact I have two instances of this issue, one being an ASP.NET and one a desktop app.
    – chiccodoro
    Aug 9, 2011 at 9:55
  • you should have no problem either way. I've had luck with the SetEnvironmentVariable function for ASP.net, Winforms, and even services. This of course is only necessary if you don't want to set these variables on the system level. If this is the only oracle client on the machine, I would just set the ORACLE_HOME and PATH system environment variables.
    – b_levitt
    Aug 9, 2011 at 15:07
  • Hi b_levitt. I tried that, unfortunately I still get the same error message (see new #9 in my updated question)
    – chiccodoro
    Aug 11, 2011 at 13:53
  • I should be more clear - you should have NO oracle files or dlls other than Oracle.DataAccess.dll with your app (which is also optional if you instead chose to GAC the dll). Make sure it's the one from the odp.net\bin folder from within your xcopy install. Make sure "specific version" in your reference property is set to true (at least you'll get a different error if this is an assembly mismatch). Confirm you also undid your #6 or changed it to specify your new xcopy loc. You can find the unmananged file search order here: download.oracle.com/docs/html/E10927_01/InstallODP.htm
    – b_levitt
    Aug 22, 2011 at 13:06
  • Process monitor might also help here as it should let you see what files and reg entries your app and it's corresponding oracle provider is trying to access: technet.microsoft.com/en-us/sysinternals/bb896645
    – b_levitt
    Aug 22, 2011 at 13:07
1

I had the same problem you have. I found most of my answers through Oracle forums and here at stackoverflow. I can't post links for reference but I can give you some things to try out.

  1. Also include OraOps11w.dll in your bin directory along with the other Oracle dll files.
  2. Go to the project properties|Reference Paths, add C:\Windows\Microsoft.NET\Framework64\v2.0.50727 or C:\Windows\Microsoft.NET\Framework64\v4.0.30319 to the Reference paths depending on which framework version the project is using.
  3. **Fuzzy part that I don't remember well: Remove the System.Data.OracleClient current reference and add the new reference from C:\Windows\Microsoft.NET\Framework64\v2.0.50727 or C:\Windows\Microsoft.NET\Framework64\v4.0.30319 to the Reference paths depending on which framework version the project is using.

See if the exception goes away.

FYI, Microsoft is dropping Oracle data provider (in ADO.NET) support in the near future. It currently works through .NET 4, but it is a good idea to start testing the native Oracle drivers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.