0

I need to refer several 32-bit dlls in my project. Basically, it contains several WCF services that connect to Oracle DB and do some CRUD operations. When I deploy my solution into IIS and set Application pool to

Enable 32-bit Applications to False, getting this exception...

System.BadImageFormatException: Could not load file or assembly 'PasswordValidator' or one of its dependencies. An attempt was made to load a program with an incorrect format

Enable 32-bit Applications to True, getting this exception...

The 'OraOLEDB.Oracle' provider is not registered on the local machine.

The connection string is:

Provider = OraOLEDB.Oracle; Data Source =lsdb; User ID =ls_Data; Password =oracle

I have installed 64-bit Oracle client, this is the problem. When I install 32-bit Oracle client, the issue is resolved. How to resolve this by having 64-bit Oracle client.

I tried to build the project by setting platform target to 64-bit, any CPU, x86. No use. If I set to 64, my DLL itself can't be loaded if I set Enable 32-bit to True (of course, expected behavior).

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
kpgu1718
  • 97
  • 4
  • 15
  • In a 32-bit application you have to use also the 32-bit Oracle Client, you cannot mix the architecture within a process. "AnyCPU" means 64-bit on nowadays 64-bit Windows, resp. 32-bit on old 32-bit Windows. You an install both 32-bit and 64-bit Oracle Client on one machine, follow this instruction: https://stackoverflow.com/questions/24104210/badimageformatexception-this-will-occur-when-running-in-64-bit-mode-with-the-32#24120100 – Wernfried Domscheit May 10 '18 at 06:31
  • Yes, we can install both on one machine. However, DBA at client side not allowing us to install the 32-bit client. Even though, I refer 32-bit DLL, Why can't I build the solution to 64-bit... – kpgu1718 May 11 '18 at 04:24
  • That's a core Windows limitation. A process can run only in one architecture. Consider to use the **ODP.NET Managed Driver** (`Oracle.ManagedDataAccess.Client`), this is just a single DLL compiled on "AnyCPU", i.e. this one works on both, 32-bit and 64-bit. – Wernfried Domscheit May 11 '18 at 05:16
  • Thank you for your suggestion. But it's not working :(. Still, it is showing same behaviour i.e. PasswordValidator.dll missing... – kpgu1718 May 16 '18 at 07:40
  • Looks like you have two different problems. One miss file `PasswordValidator.dll` the other one miss the `OraOLEDB` provider. All comments above are related to the missing OraOLEDB provider only. – Wernfried Domscheit May 16 '18 at 08:04
  • thank you. it worked out... – kpgu1718 May 27 '18 at 11:24

1 Answers1

0

To solve this,

set Enable 32-bit Applications for Apppool in IIS to True

uncheck Use the 64 bit version of IIS Express for websites and projects setting available under Tools->Options->Projects and Solutions->Web Projects

Use 64-bit version of IIS

Use ODP.NET Managed Driver (Oracle.ManagedDataAccess.Client) for Oracle DB connection not OLEDB.

Don't forget to compile by setting Target Platform to Any CPU

Thanks to Wernifried Domscheit

kpgu1718
  • 97
  • 4
  • 15
  • When you use the managed driver then it does not matter if you set 32-bit or 64-bit. – Wernfried Domscheit May 27 '18 at 11:57
  • What about 32-bit dlls referred in solution. You mean I can compile my solution to 64-bit even if I refer 32-bit dlls? – kpgu1718 May 31 '18 at 06:26
  • It does not matter. The application loads automatically the 64-bit DLL (from `%windir%\System32`) or the 32-bit DLL (from `%windir%\SysWOW64`), this is called [File System Redirector](https://msdn.microsoft.com/en-us/library/aa384187(VS.85)) See another example at https://stackoverflow.com/questions/46855084/cscript-when-called-as-a-process-in-c-sharp-only-opens-32-bit-version/46935059#46935059 – Wernfried Domscheit May 31 '18 at 06:40