0

We have a WebService that's been running for a while, there's about 6~ projects on it. Recently, we had to support a C++ 32 bit library, I tested and I had to set the project's target platform to x86 or I'd get the BadImageFormatException. So this new project is set to compile on x86, but everything else is set to AnyCPU.

After publishing the WebService, I get the error Unable to find ?.dll when calling the function.

Is there anyway I can add this new project as x86 without having to set my WCF to x86 as well, or am I doing something wrong and this should've worked?

Danicco
  • 1,573
  • 2
  • 23
  • 49

1 Answers1

1

It is possible but all binaries (.exe-s and .dll-s) must share the same target platform for it to work. You cannot load a 32-bit DLL into a 64-bit process or the other way around.

If you're hosting your web service under IIS, the target platform of the app pool determines what kind of DLL-s you can load.

If you have exported functions in your unmanaged DLL-s, your P/Invoke declarations must also match the target platform - specifically, if you pass pointers, those will have to be correctly mapped to 32/64-bit pointers. (Usually IntPtr takes care of this.) P/Invoke declarations really turn into possible problems if you support both platforms with a single source base (compiled into platform-specific binaries).

Depending on what you're trying to do, you may also need to deal with handling platform-specific references. This question has more detail about that.

Community
  • 1
  • 1
xxbbcc
  • 16,930
  • 5
  • 50
  • 83