开发者

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

开发者 https://www.devze.com 2023-01-17 02:14 出处:网络
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

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: Cou开发者_如何学运维ld 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.


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


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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号