Skip to content

Same code starting wkhtmltopdf process works on netcoreapp3.1 but fails on net5.0 on Linux #46469

@gurustron

Description

@gurustron

Description

Repro.

Following code starting process and reading stdout works fine in netcoreapp3.1:

    internal class Program
    {
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            using (var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "wkhtmltopdf",
                    Arguments =
                        "-q -B 8 -L 8 -R 8 -T 8 --print-media-type --enable-local-file-access -s Letter -O Portrait - -",
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    RedirectStandardInput = true,
                    CreateNoWindow = true
                }
            })
            {
                process.Start();

                byte[] array;

                var html = "test";
                using (var standardInput = process.StandardInput)
                {
                    standardInput.WriteLine(html);
                }

                using (var memoryStream = new MemoryStream())
                {
                    using (var baseStream = process.StandardOutput.BaseStream)
                    {
                        var buffer = new byte[4096];
                        int count;
                        while ((count = baseStream.Read(buffer, 0, buffer.Length)) > 0)
                            memoryStream.Write(buffer, 0, count);
                    }

                    var end = process.StandardError.ReadToEnd();
                    if (memoryStream.Length == 0L)
                        throw new Exception(end);
                    process.WaitForExit();
                    array = memoryStream.ToArray();
                }

                Console.WriteLine(array.Length);
            }
        }
    }

but fails in net5.0 with:

System.Exception: QPainter::begin(): Returned false
Exit with code 1, due to unknown error.

Configuration

  • dotnet --version: 5.0.101
  • Ubuntu 20.04.1 LTS
  • wkhtmltox_0.12.6-1.bionic_amd64

Regression?

Works in netcoreapp3.1

Other information

related:

  1. Linux version cannot write on STDOUT when wkhtmltopdf used as a child-process. wkhtmltopdf/wkhtmltopdf#3119
  2. Failure on .NET 5.0 fpanaccia/Wkhtmltopdf.NetCore-deprecated#46 (comment)
  3. QPainter::begin(): Returned false Exit with code 1, due to unknown error. .net 5 docker linux fpanaccia/Wkhtmltopdf.NetCore.Example-deprecated#14

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions