How To Resolve: Could not load file or assembly ‘xxxx’ or one of its dependencies. An attempt was made to load a program with an incorrect format. [Programming]

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

  1. Open Properties Window of the project(dll that was part of the error message).
  2. Select Build tab
  3. Change ‘Platform Target‘ it to ‘Any CPU’
  4. Save your changes.
  5. Build and re-publish application to Windows Azure. Problem Solved!

project_properties

Leave a Comment

Your email address will not be published. Required fields are marked *