Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wcf

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.

like image 707
Contango Avatar asked Sep 20 '10 20:09

Contango


3 Answers

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

like image 194
Stretch Avatar answered Nov 13 '22 22:11

Stretch


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?

like image 28
Sean Fausett Avatar answered Nov 13 '22 22:11

Sean Fausett


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

like image 35
Contango Avatar answered Nov 13 '22 22:11

Contango