Emanuele
Emanuele

Reputation: 664

Is there an issue using TuesPechkin in .NET 6 WebApi?

I'm trying to convert Html to Pdf in a .NET 6 WebApi project using TuesPechkin. My application is hosted by IIS. I downloaded libraries from NuGet. I have Visual C++ 2013 runtime installed.

I tried using:

  1. TuesPechkin.Wkhtmltox.AnyCPU
  2. TuesPechkin.Wkhtmltox.TuesPechkin + TuesPechkin.Wkhtmltox.Win64

I have already successfully developed the same case in .NET 4.5 with a 32 bit version.

Pdf Converter Class

public static class TuesPechkinPdfConverter
{
    public static IConverter Converter { get; } = new ThreadSafeConverter(
        new RemotingToolset<PdfToolset>(new WinAnyCPUEmbeddedDeployment(new TempFolderDeployment())));
}

It's the same using Win64EmbeddedDeployment.

Method

public byte[] ConvertHtmlToPdf(byte[] htmlFileContent, string filename)
{
    HtmlToPdfDocument pdfDoc = new HtmlToPdfDocument()
    {
        GlobalSettings =
        {
            ProduceOutline = true,
            DocumentTitle = filename,
            PaperSize = PaperKind.A4,
            Margins =
            {
                All = 1,
                Unit = Unit.Centimeters
            }
        }
    };

    ObjectSettings objectSettings = new ObjectSettings()
    {
        RawData = htmlFileContent
    };

    pdfDoc.Objects.Add(objectSettings);

    return TuesPechkinPdfConverter.Converter.Convert(pdfDoc);
}

I got the following runtime error:

System.TypeLoadException: 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'

The app pool is configured as follows:

Enable 32bit application: false

Load User Profile: true

Identity:

Pipeline mode: Integrated

.NET CLR: No managed code

I tried to install System.Security.Principal or System.Security.Principal.Windows without success.

Upvotes: 2

Views: 232

Answers (0)

Related Questions