Trying to call third party dll from Azure Function V2 I get an exception

0

I strictly follow this sample: https://odetocode.com/blogs/scott/archive/2018/02/14/pdf-generation-in-azure-functions-v2.aspx

I download the three files from the DinkToPdf repository

Problem is when I add either 32bit OR 64bit DLLs, I get the following error:

One or more errors occurred. (An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B))

on this code in particular:

private static byte[] BuildPdf(string html)
    {
        byte[] arr = null;

        try
        {
            arr = pdfConverter.Convert(new HtmlToPdfDocument() { Objects = { new ObjectSettings { HtmlContent = html } } });
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex);
        }

        return arr;
    }

My Azure Function V2 .net Core project is set to Any CPU with no option for other. I saw other posts on Stack Overflow about this error and I feel that this is different because other people are talking about two projects that have control over and there is some differences in the architecture, but here I just point a few binaries and no matter if they are 32 or 64 the error stays. Also I saw that some people change settings of the IIS and I don't have such. Any ideas? Thanks!

enter image description here

c#
.net
azure
azure-functions
wkhtmltopdf
asked on Stack Overflow Oct 23, 2018 by nmrlqa4 • edited Oct 25, 2018 by Jerry Liu

1 Answer

1

One or more errors occurred. (An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B))

This error is caused by using 64 bit dll. By default, VS works with 32 bit Function CLI hence the error is expected. The bit is not the problem, we can use x64 CLI with several steps.

Problem is one tricky error Qt: Could not initialize OLE (error 80070005).

Function hangs when our html content has some javascript tags or references. See the test done by Travis. When js is removed Function returns PDF successfully but the error message persists.(I assume it doesn't matter as we get a complete PDF as expected.)

If this restriction is not acceptable, install package OpenHtmlToPdf, change your code as below. Also you can try other packages.

private static byte[] BuildPdf(string html)
{
    return Pdf.From(html).Content();
}

Note that this method doesn't work in Function on Consumption plan or Free App service plan.

answered on Stack Overflow Oct 25, 2018 by Jerry Liu • edited Oct 25, 2018 by Jerry Liu

User contributions licensed under CC BY-SA 3.0