0

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?

Community
  • 1
  • 1
smilu
  • 859
  • 7
  • 30
  • 53
  • I'm just making a stab at it here but ... What version of the Oracle Client is installed on the web server (is it the full client or instant client)? And is it 32 bit or 64 bit? – Tomás May 19 '17 at 08:57
  • It is from .Net Assemblies for 4.5.1. The version of the dll is 4.0 and it is 64 bit I believe. – smilu May 19 '17 at 09:22

2 Answers2

0

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.

Tomás
  • 535
  • 6
  • 23
  • I tried the changing it to x86. Still i get the same BadImageFormat exception – smilu May 19 '17 at 10:34
  • No, AnyCPU means the process that loads the DLL is what determines what mode the DLL will use. For a web site under IIS, that's fully controlled from the "Enable 32-bit" setting. Forcing the compilation to 32-bits in this case doesn't help - use the setting. It sounds like the Oracle library is installed on the server as a 64-bit DLL only (I don't have any experience working with that library) – Euro Micelli May 20 '17 at 18:54
0

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

Community
  • 1
  • 1
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • This OracleClient is working for ages for us in the 64bit Server. Now the problem suddenly occurred when we we had to Enable 32bit in the IIS. – smilu May 19 '17 at 10:32
  • Yes, in 32bit mode `System.Data.OracleClient` is (still) working. Nevertheless it is outdated for more than a decade. `System.Data.OracleClient` cannot work in 64 bit application - it is not possible. – Wernfried Domscheit May 19 '17 at 12:18
  • I don't know. I was also under the same impression it should only work as 32 bit. Our Servers are upgraded to 64 bit for more than 2 years. And in our latest servers, only 64 bit Oracle client is installed. But still System.Data.OracleClient works without enabling 32bit in IIS Application pool. But, in the same server if I enable 32bit it will stop working saying BadImageFormat. This is why it confuses me too. – smilu May 20 '17 at 05:40
  • Maybe use [Process Monito](https://technet.microsoft.com/de-de/sysinternals/processmonitor.aspx) from sysinternals to see which DLL are really loaded – Wernfried Domscheit May 20 '17 at 18:34
  • I finally installed 32bit oracle also into the server. Now, with both 32bit enabled or not, works. So Thanks for everyones suggestions – smilu May 21 '17 at 11:52