Monday 28 June 2010

BadImageFormatException with 32-bit DLLs on 64-bit server in ASP.NET .NET 4.0

I faced a problem after upgrading my ASP.NET site from .NET 3.5 to 4.0 where I started getting the following exception:

“BadImageFormatException: Could not load file or assembly '<32 bit Assembly>' or one of its dependencies. An attempt was made to load a program with an incorrect format.”

After searching for a while in internet, the problem was clear – my 64 bit windows is refusing to load the 32bit DLL when starting my ASP.NET application. The only problem left was how to fix this. Looking little bit more, the solution was very simple (for the installation of IIS7 I am running)

Under ‘Internet Information Services (IIS) Manager"’ –> ‘Application Pools’ locate the pool used by your application (The default name will be ‘ASP.NET v4.0’). Right Click it and open the ‘Advanced Settings’. Under ‘General’ find the ‘Enable 32-Bit Applications’ and change the setting to ‘True’

That's it.

Hope this helps.