Thursday 23 June 2011

Could not load file or assembly XX. System.BadImageFormatException

I got this error when I was working with Silverlight RIA application which works on MVVM pattern. Everything was running smoothly before when I was using VSTS2010 internal web server. As soon as I host my asp.net application which host silverlight application to IIS 7 of windows 7 I got the above error.

Although I was using dll which was built on any CPU platform. After some digging I found out that there is a setting in IIS 7 in Application Pool that you can set.
Open IIS using InetMgr command, locate & click your web application. In the action tab select Advanced Settings and view your application pool.
Now goto application pool and locate the pool viewed in last step. Click your pool and select Advanced Settings from action tab. In General settings Enable 32-Bit Applications set this value to true.
After setting this when I tried to run the application, I got "Login failed for user 'IIS APPPOOL\ASP.NET v4.0'" error. You may overcome this by going to Process Model in Application pool and in Identity setting, change ApplicationPoolIdentity to NetworkService or LocalSystem and you're go.

Make sure to remove anonymous access and add windows authentication (if using windows auth) to your asp.net web application.