简体   繁体   中英

Attempt to load Oracle client libraries threw BadImageFormatException IIS System.Data.OracleClient

The Story: My website runs in System.Data.OraceClient(I cannot change the dll due to various technical reasons). Now, I have an third party DLL integrated to my website which is 32 bit. When I run from Visual studio everything runs perfectly, but when I publish it to IIS, it throws the above error.

Now Solutions are: Enable 32 bit in IIS Application pool

When 32bit is enabled the Third party DLL will start to work and System.Data.Oracle client fails with BadImageFormat exception

Disable 32 bit in IIS Application pool.

When 32 bit is disabled System.Data.OracleClient will start to work and the third party DLL will fail with the below error.

Retrieving the COM class factory for component with CLSID {xxxxx} failed due to the following error: xxxxxx Class not registered

-- This class is registered. That is why it works when 32 bit is enabled.

Now, I am in a situation only one dll will work at a time. Is there a workaround to make my System.Data.OracleClient run when 32Bit is enabled in Application pool without trying to migrate my entire application to Oracle Data Access?

I am thinking the only way to achieve this is to build your web application as 32 bit and that way let it use a 32 bit client. Then everything is 32 bit. Make sure that your Web Application is built for x86 . Do not build as AnyCpu as that will default to the target platform's x64.

System.Data.OracleClient is deprecated for ages and should not be used anymore. It is available only for x86 (32 bit), when Microsoft stopped developing of System.Data.OracleClient 64-bit Windows was not that common yet.

Better use the ODP.NET provider from Oracle, it is available for x86 and x64.

Check also this instruction: BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM