Skip to content

WkhtmlToPdf crash the application with AccessViolation exception #138

@trungdang194

Description

@trungdang194

We are encoutering an issue with WkhtmlToPdf-Dotnet that cause the app to crash. It not always encouter app crash, only a few times it happens

We get the log from windows event log
Application: MyProgram.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
at WkHtmlToPdfDotNet.WkHtmlModuleWin64.wkhtmltopdf_convert(IntPtr)
at WkHtmlToPdfDotNet.BasicConverter.Convert(WkHtmlToPdfDotNet.Contracts.IDocument)
at WkHtmlToPdfDotNet.SynchronizedConverter+<>c__DisplayClass4_0.b__0()
at System.Threading.Tasks.Task`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].InnerInvoke()
at System.Threading.Tasks.Task.Execute()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
at System.Threading.Tasks.ThreadPoolTaskScheduler.TryExecuteTaskInline(System.Threading.Tasks.Task, Boolean)
at System.Threading.Tasks.TaskScheduler.TryRunInline(System.Threading.Tasks.Task, Boolean)
at System.Threading.Tasks.Task.InternalRunSynchronously(System.Threading.Tasks.TaskScheduler, Boolean)
at WkHtmlToPdfDotNet.SynchronizedConverter.<.ctor>b__3_0()
at System.Threading.Tasks.Task.Execute()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Nuget package version:
Haukcode.WkHtmlToPdfDotNet v1.5.95
Build windows x64

Code:

 static IConverter _converter = new SynchronizedConverter(new PdfTools());
 static void Main(string[] args)
    {
        var tasks = new List<Task>();
        for (int i = 0; i < 100; i++)
        {
            var t = Task.Run(() =>
            {

                HtmlToPdfDocument _document = new HtmlToPdfDocument
                {
                    GlobalSettings =
                    {
                        Orientation = Orientation.Landscape,
                        Outline = false,
                        PaperSize =PaperKind.A4, 
                        Margins = new MarginSettings(0,0,0,0)
                    },
                    Objects = {new ObjectSettings
                    {
                        HtmlContent = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consectetur mauris eget ultrices  iaculis. Ut                               odio viverra, molestie lectus nec, venenatis turpis.",
                        LoadSettings = new LoadSettings { BlockLocalFileAccess = false },
                        WebSettings = new WebSettings { EnableJavascript = false, LoadImages = true, Background = true }
                    }}
                };
                MemoryStream ms = new MemoryStream(_converter.Convert(_document));
                Console.WriteLine($"{i}");
            });
            tasks.Add(t);
        }
        Task.WaitAll(tasks.ToArray());
        Console.WriteLine("Done");
        Console.ReadLine();
    }

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