1

I am using a library (DLL) that uses the Oracle.DataAccess DLL to connect to the database. I am doing in in C# .NET framework 3.5

When I attempt to compile, the compilation takes place, but the executable throws this error message.

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

Is there some way to get around this? What could be causing this to happen?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
abhi
  • 3,082
  • 6
  • 47
  • 73

2 Answers2

3

The dll for that ODBC is likely a 32bit only dll. Are you using this on a 64bit machine? If you are, IIS 7 has an option in the application pool that will allow you to "Enable 32-Bit Applications".

Joel Etherton
  • 37,325
  • 10
  • 89
  • 104
  • I am using a 32 bit OS. I am on windows XP. The OracleDataAccess.dll is a 64 bit dll. I just found this by using the dumpbin. This is what my usage is 32 bit exe --> 32 bit Dll --> 32 bit dll --> 64 bit dll (Oracle DataAccess.dll) – abhi Jun 11 '10 at 14:03
2

One possibility: Your programm is compiled with x64 or AnyCPU on a 64bit machine but the dll has been compiled with support for x86 only.
You can overcome this if you change the plattform of your Solution (or project) to x86.

I know you can force a 64bit Assembly to run as a 32bit app with:

corflags /32bit+ Oracle.DataAccess.dll

That works because the MSIL code is not bound to a processor architecture. However I never tried it the other way:

corflags /64bit+ Oracle.DataAccess.dll

so I can't tell if this works. And I propably won't work if the dll has unmanaged dependencies.

Jürgen Steinblock
  • 30,746
  • 24
  • 119
  • 189
  • corflags : error CF012 : The specified file is strong name signed. Use /Force t o force the update. If I use Force, this is the message I get. corflags : warning CF011 : The specified file is strong name signed. Using /Force will invalidate the signature of this image and will require the assembly to be resigned. – abhi Jun 11 '10 at 14:04
  • When using force you will get the message, but the file will be modified, too. http://stackoverflow.com/questions/1525857/corfflags-warning-cf011-about-strong-name-signed-even-after-force If you don't need the strong name then you should be fine. Anyway, I would recommend to set your main projects (the .exe) target plattform to x86 (look at my first suggestion) and leave your own dll's as "Any CPU". – Jürgen Steinblock Jun 11 '10 at 14:21
  • None of these are my own DLLs. The exe is the only code that I own. 32 bit exe --> 32 bit Dll --> 32 bit dll --> 64 bit dll (Oracle DataAccess.dll) I have set the executable to target x86 platform. Changing that is not proving to be useful. – abhi Jun 11 '10 at 14:24
  • Is this dll an original Ocacle file or just a third party dll that is named "Ocacle.DataAccess.dll"? If it is from Oracle itself, grab a 32bit copy (propably from here: http://www.oracle.com/technology/software/tech/windows/odpnet/index.html) and replace the dll with that. – Jürgen Steinblock Jun 11 '10 at 14:54
  • I did just that. Thanks SchlaWiener. I also had to clear teh GAC using GACUtil.exe Now my program throws a warning upon compilation, but it executes just I like I want it too. – abhi Jun 11 '10 at 15:20