Saturday 16 February 2013

Debug a x86 WCF Service on a x64 Platform

The Windows Communication Foundation (WCF), previously known as "Indigo", is a runtime and a set of APIs in the .NET Framework for building connected, service-oriented applications. [Wikipedia]

This issue was occurred on my previous assignment.
In that assignment, I need to create a WCF Service Library. For maximal compatible, I set the platform as x86.


After some coding works,I launched the debugger...
But there was an exception:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\celeron533\Dropbox\5041\Assignment2_Project\Airline2_Server\AirLineServiceLibrary\bin\x86\Debug\AirLineServiceLibrary.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.


The reason is, Service Library is a DLL file and need a program to host and call it. In Visual Studio 2010, this host program is:
Microsoft Visual Studio 10.0\Common7\IDE\WcfSvcHost.exe
When installing the VS2010, install wizard detected that the system is x64 so it copy the x64 version of WcfSvcHost.exe
However, as the message box indicated, this x64 service host could not load and run x86 service DLLs.

Solution (from msdn):
http://social.msdn.microsoft.com/Forums/en/wcf/thread/2e29a4aa-e587-43ef-bf50-329b7cd3eefb



  1. Copy WcfSvcHost.exe from C:\program files (x86)\Microsoft Visual Studio 9.0\Common7\IDE to a local directory. Keep a backup copy of this file, of course.
  2. Start a Visual Studio 2008 Command Prompt (one of the links from the start menu -> Visaul Studio 2008)
  3. "cd" to the directory where your copy of WcfSvcHost is located.
  4. Execute the command "corflags /32BIT+ /FORCE WcfSvcHost.exe"
  5. Copy the exe back to where you found it.




Now it works!

No comments:

Post a Comment