Skip to content

Process terminated. A callback was made on a garbage collected delegate of type 'WkHtmlToPdfDotNet ! WkHtmlToPdfDotNet. StringCallback: : Invoke' #135

@ninhngochieu

Description

@ninhngochieu

I have been using this library in production for over a year, but recently, our server has been crashing and restarting several times a day when generating reports. This issue may be related to an increase in the number of users.

image

How can I resolve this problem? I am using .NET 6 and library version v1.5.86. My current implementation is as follows:

       services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
    protected async Task<ExportResult> ConvertAsync(string folderPath, string fileName, string htmlContent, 
        bool isLandscape = false)
    {
        var saveFile = $"{folderPath}\\{fileName}.pdf";
        var doc = new HtmlToPdfDocument()
        {
            GlobalSettings = {
                    ColorMode = ColorMode.Color,
                    Orientation = isLandscape ? Orientation.Landscape: Orientation.Portrait,
                    PaperSize = PaperKind.A4,
                    Margins = new MarginSettings() { Top = 2, Bottom = 10, Left = 2, Right = 2 },
                    Outline = false,
                    Out = saveFile
                },
            Objects = {
                    new ObjectSettings() {
                        PagesCount = true,
                        HtmlContent = htmlContent,
                        WebSettings = { DefaultEncoding = "utf-8" },
                    }
                },
        };
        _converter.Convert(doc);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions