tags:

views:

17

answers:

2

Hi,

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.

+1  A: 

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?

Sean Fausett
The client is the EXE. The EXE calls functions of the WCF web service, the WCF service calls the Matlab functions in turn. I understand that DLL's need to be marked as "Any CPU", but if I do this, then I can't instantiate the Matlab class to call Matlab functionality as it gives an error.
Gravitas
Presumably the client is actually using a proxy to the WCF service. So what is hosting the WCF service - IIS, a console app, or a Windows service?
Sean Fausett
Problem solved. Thanks for putting me on the right track. See: http://stackoverflow.com/questions/3755761/i-cant-compile-a-standard-wcf-service-library-in-x86-format. I had a solution with two projects: one project was a console app which consumes services from the WCF Service Library, and one project was the WCF Service Library. When I ran the console app, it automatically executed the service, hosted with "WcfSvcHost". I've demonstrated that if I host my 32-bit WCF Service Library using a different method, namely IIS, it won't throw any exceptions just because its compiled in 32-bit mode.
Gravitas
This link explains more about the methods to host WCF services: http://msdn.microsoft.com/en-us/library/bb332338.aspx#msdnwcfhc_topic3
Gravitas
A: 

I found a couple of good solutions which solved all my problems. I documented it here: http://stackoverflow.com/questions/3755761/i-cant-compile-a-standard-wcf-service-library-in-x86-format

Gravitas