Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.TypeLoadException: 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' (compatibility .NET 6) #197

Open
codeweb opened this issue Sep 4, 2023 · 1 comment

Comments

@codeweb
Copy link

codeweb commented Sep 4, 2023

I'm trying to convert Html to Pdf in a .NET 6 WebApi project.
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

@codeweb codeweb changed the title System.TypeLoadException: 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' System.TypeLoadException: 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' (compatibility .NET 6) Sep 5, 2023
@codeweb
Copy link
Author

codeweb commented Sep 5, 2023

@tuespetre Can we say the project is not compatible with .NET 6?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant