Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ODP.NET Load file or assembly

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.

like image 575
Wjdavis5 Avatar asked May 18 '12 18:05

Wjdavis5


2 Answers

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.

like image 176
Reed Copsey Avatar answered Sep 28 '22 18:09

Reed Copsey


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.

like image 43
aquinas Avatar answered Sep 28 '22 19:09

aquinas