ASP.NET tip: force Visual Studio to run a 64-bit version of IIS Express web server
Posted: (EET/GMT+2)
Most older ASP.NET web applications (say, built with the WebForms technology) happily run as 32-bit applications. As you are working with the application, at some point, you will probably ask the question: could this application run as 64-bit?
Usually, the answer is yes. However, even if the application itself would happily build as a 64-bit application, you might run into the following error message when building and running your application as x64 application:
Could not load file or assembly XXX or one of its dependencies. An attempt was made to load a program with an incorrect format.
Although there are many possible reasons for this error, one of them is actually related to your testing environment, and not your code: the IIS Express edition you are using. Visual Studio by default runs ASP.NET 2.x–4.x web applications through IIS Express, but by default, it runs as a 32-bit process.
Quite naturally, you cannot load a 64-bit web application you've built into a 32-bit host process.
The solution is to change Visual Studio's options. Here's how, if you are using Visual Studio 2015: go to Tools/Options menu command, and then from the left of the options dialog, navigate to "Projects and Solutions" and then "Web Projects". Now on the right, enable/check the option to "Use 64 bit version of IIS Express for web sites and projects".
If, however, you are using an older version of Visual Studio that doesn't have this option available, you can update the registry. For instructions, see here.
Problem solved, most of the time!