WCF Service with a thid-party DLL: "BadImageFormatException" or "PInvoke unbalanced stack" exception

1

I am trying to use DinkToPDF in a WCF service to generate a PDF file from HTML. This library is a wrapper for the wkhtmltopdf library. This requires having the 32 bit or 64 bit .dll for wkhtmltopdf in the solution root folder.

When the DinkToPDF "BasicConverter.Convert()" method is called, I get the following exception (with 64 bit wkhtmltopdf dll):

'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'

This is with the 32 bit wkhtmltopdf dll:

'A call to PInvoke function 'DinkToPdf!DinkToPdf.WkHtmlToXBindings::wkhtmltopdf_init' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.'

All this code works fine in a console app, using the 64 bit dll, but throws the above exception when in a WCF service. From googling I could see this may have something to do with the way ISS handles x64/x86 builds but when it comes to that side of things, I am way out of my league.

I appreciate any advice.

Thanks

wcf
iis
dll
wkhtmltopdf
asked on Stack Overflow Jan 7, 2018 by S-Vuk • edited Jan 7, 2018 by S-Vuk

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0