While enhancing one of Windows Azure web application today, I was struck with the following error that occurs only Windows Azure environment
Could not load file or assembly ‘xxxx’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
When the web application is tested on local development box, everything works fine. The error message suggests that a specific dll is missing in the deployed folder. I verified the folder and it contains the dll. After debugging sometime, the problem is identified as incompatible Target CPU settings of the dll mentioned in the error message.
The dll specified in the error was built with Target CPU set to x86(development environment is also x86 so it worked). As Windows Azure environment is x64 environment, IIS was raising the error even though the dll was available in the required folder.
How To Fix The Error
Here are the simple steps to be followed for fixing the issue
- Open Properties Window of the project(dll that was part of the error message).
- Select Build tab
- Change ‘Platform Target‘ it to ‘Any CPU’
- Save your changes.
- Build and re-publish application to Windows Azure. Problem Solved!