How do I compile a WCF Service Library in 32-bit mode?

I can reference Matlab code from a x86 based project, but not from an x64 project.

I can build the WCF Service as "Any CPU", but not x86. When I attempt to build as x86 only, it gives the following error:

---start error---
System.BadImageFormatException: Could not load file or assembly 'file:///D:\backtest\WcfServiceLibrary.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
---end error---

Thus, I'm stuck: how on earth do I provide Matlab calls via WCF? Its like some weird form of developers XOR.

Any ideas on how to either (a) compile the WCF Service Library in 32-bit mode, or (b) work around the issue?

I have Win7 x64, MSVS 2010.

Answers


WcfServiceLibrary is a DLL, so should be built as "Any CPU". Only EXE projects hosting all the other DLLs need to be marked as "x86" or "x64" as required. Which project is the EXE in this case?


Your problem is actually the WCF Test Client complaining that your WCF Service Library is 32bit. This is because by default, the WCF Test Client always runs in 64 bit mode.

I found the following steps on this blog which makes the WCF Test Client run in 32bit mode - and therefore you will not see the error you have posted.

  1. Copy WcfSvcHost.exe and WcfTestClient.exe from C:\program files (x86)\Microsoft Visual Studio 10.0\Common7\IDE to a local directory. Keep a backup copy of this file, of course.
  2. Start a Visual Studio 2010 Command Prompt (one of the links from the start menu -> Visaul Studio 2010)
  3. "cd" to the directory where your copy of WcfSvcHost is located.

  4. Execute the command "corflags /32BIT+ /FORCE WcfSvcHost.exe"

  5. Execute the command "corflags /32BIT+ /FORCE WcfTestClient.exe"

  6. Copy the files back to where you found it.

Now your WcfSvcHost and WcfTestClient will be running in 32 bit mode, and you won't get your error


I found a couple of good solutions which solved all my problems. I documented it here: I can't compile a standard "WCF Service Library" in x86 format


Need Your Help

How can I "pretty" format my JSON output in Ruby on Rails?

ruby-on-rails ruby json pretty-print

I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted.

Where do I set the application icon in an iphone app

iphone ios xcode icons

I wrote an app for iphone. All is working. I see it in an ipod. I have done all the testings and thanks to you guys I was able to resolve all my issues so far. Where do I set my application ico...