C# ODP.NET Load file or assembly

14,609

Solution 1

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.

Solution 2

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.

Share:
14,609
Wjdavis5
Author by

Wjdavis5

By Day: Senior Developer @ Synovia Solutions LLC. By Night: Probably still Senior Developer @ Synovia Solutions LLC. If not, enjoying good food, wine and maybe playing xbox. Weekend: Warrior

Updated on June 23, 2022

Comments

  • Wjdavis5
    Wjdavis5 about 2 years

    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.

  • one.beat.consumer
    one.beat.consumer over 11 years
    For web applications this means the app pool must run 32-bit and the 32-bit Oracle Client is required. What is the solution for 64-bit web server and oracle client, when using 4.112.3? Copy local is 32-bit. Boom. Without it, the client's GAC'd copy 4.112.2 is used. Boom. Copying 64-bit new version to bin blows up saying its provider factory is missing an interface. Is it trying to use old GAC_64 version again? Or is something missing from web.config to tell it to use the new provider in the bin copy?