tags:

views:

144

answers:

2

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?

+2  A: 

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
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 is32 bit exe --> 32 bit Dll --> 32 bit dll --> 64 bit dll (Oracle DataAccess.dll)
abhi
A: 

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.

SchlaWiener
corflags : error CF012 : The specified file is strong name signed. Use /Force to 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
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-forceIf 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".
SchlaWiener
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
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.
SchlaWiener
I did just that. Thanks SchlaWiener. I also had to clear teh GAC using GACUtil.exeNow my program throws a warning upon compilation, but it executes just I like I want it too.
abhi