0
votes

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.

1
How are you hosting the service? IIS? If so check that the Application Pool has "Enable 32-bit Applications" set to false.lesscode
I don't think that I am... That said, I am new to C# and WCF services in general. I am using the System.ServiceModel and it appears to just be hosted using the debugger on localhost for http access from the client. Moreover, I do not think the .dll the service or the client are 32bit -- I think its 64bit across the board.sam
Are you using some third-party DLL? If so, check its bitness. Its probably 32-bit. All DLL's need to be 64-bit, also the one you references in your projectFrode
Yes this is a third-party DLL. They have provided both a 32 and a 64 bit version. Which both work properly when referenced using a desktop app. The problem is coming from when I attempt to expose some of the functions as a WCF service (using a separate VS project) regardless of what I compile the service as, I get the System.BadImageFormatExceptionsam
Actually, I think that by default a WCF service project gets hosted by VS automatically in IIS Express when you debug. IIS Express itself defaults to 32-bit. Check Task Manager while your service is running for the Platform (bitness) of iisexpress.exe.lesscode

1 Answers

0
votes

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.