11
votes

I recently started testing on a C# (4.0) app that uses ODP.NET (Oracle.DataAccess 4.112.3)

I set this project to target any platform and publish the app.

When I run the program on the client machine I receive:

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

Like I said I've targeted 'Any CPU' and I've also embedded the Oracle.DataAccess assembly with the app.
I get this error on machines that have the Oracle client installed as well as machines that do not.

Any help is appreciated.

4
You've changed 'Copy Local' to True on the properties of the Oracle reference right? - carny666

4 Answers

18
votes

Like I said I've targeted 'Any CPU'

This is likely the problem.

The Oracle.DataAccess has separate versions for 32bit and 64bit systems. If you are developing on a 32bit machine, and then deploying on a 64bit OS, you will receive this message.

You could easily work around this by building your application to target x86, and deploying the 32bit version of the data access components.

4
votes

As Reed Copsey said, there are two different DLLs. When you target ANYCpu, your app will run in 64 bit on a 64 bit machine, and 32 bit on a 32 bit machine. Therefore, if you want your app to work on 32 or 64 bit and run in AnyCPU mode, you should change the reference of Oracle.DataAccess to Specific Version=false and copy local = false. When you deploy to a client, they should have the oracle dll in the their GAC and it should pick up the correct version automagically.

0
votes

You should perhaps check if the Oracle.DataAccess assembly has any dependencies in your machine and that it is missing in the client machine.

0
votes

From debug Any cpu at top change the optin to debug X64, though internally Any CPu points to X64 only but that does not work, try to change it to x64 and it should work like a charm