I had written this post about the BadImageFormatException, when I had found again this error. Why? The solution in my linked post is simply and clear, it works! What’s difference? That was my first time I found this error while developing a WCF.. but does it matter? Or the error is somewhere else? After some struggling hours, here is my solution to this problem when working with WCF.

Like in the above linked post, also in this project I was importing some dll. It was perfect: project “Any CPU”, using only dll x64 version. All consistent, but again this error, with the message “Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format.“.

The solution is simply, but hard to find. The fault is of IISExpress: my PC in 64 bit, but, for some reasons, IISExpress set WCFs as x86 as default. To solve this error, you need to make one registry change if you want to run IIS Express as a 64-bit process by default. Use one of the methods, below.

1) Command-Line:

reg add HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\WebProjects /v Use64BitIISExpress /t REG_DWORD /d 1

2) Regedit:

  1. Navigate to: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\WebProjects
  2. Make sure there is a REG_DWORD value named “Use64BitIISExpress”.  If not, create it.
  3. Set its value from 1 (default = 0).

WARNING: before to do one the of the above operations, close your Visual Studio instance(s). If you don’t do it, you have to restart VS after the reg fix.

Solutions tested within Windows 7 64 bit and Visual Studio 2013.