Wednesday, March 11, 2015

Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format. - WCF IIS Hosting error

“Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format” is an error which you get while hosting the WCF service in IIS.

Lets see the complete exception details first,

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

image

Reason for this error:

You get this error normally when you try to host a WCF service developed in Windows 32 bit machine and you are trying to host this in a 64 bit machine.

Solution to this issue is a simple one, you just need to change the settings in IIS to enable 32 bit application hosting.

Lets see the step step by actions to change this settings.

Open IIS --> Press Start button + R and then type inetmgr.

Expand your server and then click on Application Pools

In the list of application pools select the application pool which is being used by your new WCF service. And then click on the “Advance Settings…”

image

In Advance Settings dialog change the Enable 32-Bit Applications settings from False to True and Click OK.

image

Now you browse your WCF service and see the result. I am sure your error would have disappeared.

No comments: