C# DLL works fine locally, but not when exposed as WCF service

0

I have built a desktop app that controls a piece of 3rd party hardware using their provided .dll (I am relatively confident that this is a 64bit .dll since it is running fine in VS2015 compiled with either AnyCPU or x64). Everything works just as expected when used as a desktop app.

I am now attempting to expose those same commands as a WCF service to allow a client app to control the hardware remotely. When the client connects I get:

An exception of type 'System.BadImageFormatException' occurred in mscorlib.dll but was not handled in user code

Additional information: Retrieving the COM class factory for component with CLSID {58DB561E-0186-11D5-BBB6-00508B35B332} failed due to the following error: 800700c1 is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).

If there is a handler for this exception, the program may be safely continued.

I am referencing to the same .dll as the desktop app, and calling the same functions. The client is also a 64bit application (currently still running on the same machine). Communication between client-service can already be verified with a simple Hello World function.

What am I missing? Why does the .dll work smoothly in one case and not the other?

Edit: I can rule out the client application from this, as I can trigger the error using invoke in the WCF Test Client application that launches from VS2015. This is definitely something wrong with the service application. Also, I can compile it for 32bit or for 64bit and they both give the System.BadImageFormatException.

c#
wcf
dll
asked on Stack Overflow May 19, 2016 by sam • edited Jun 20, 2020 by Community

1 Answer

0

Well, for anybody else who may find themselves in this situation here's how it seems to have turned out:

The third-party .dll came in both a 32 and a 64 bit version. I ran regsvr.exe on one version but not on the other(at this point I'm not sure which one was which). They are named the same, but located in different directories, it seems to have caused some confusion, and would allow me to reference the .dll but crash when it was called.

Mystery solved -- it's always the little details.

answered on Stack Overflow May 19, 2016 by sam

User contributions licensed under CC BY-SA 3.0