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

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

Open
ninhngochieu opened this issue Sep 4, 2024 · 2 comments

Comments

@ninhngochieu
Copy link

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);
    }
@HakanL
Copy link
Owner

HakanL commented Sep 4, 2024

I haven't seen this error before, and your code looks correct. I wonder if there could be some special scenario on Linux where the GC is removing the callbacks, but obviously it's just speculation and hard to figure out. I've checked the code in the converter and I can't see anything obvious, plus a lot of people are using this, so it's odd that nothing has surfaced so far. Perhaps try an upgrade to .NET7 or 8?

@ninhngochieu
Copy link
Author

@HakanL I'll give it a try, thank you so much for your support

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

2 participants