net-core-html-to-image icon indicating copy to clipboard operation
net-core-html-to-image copied to clipboard

issue with create image from a url

Open brianjmitchell opened this issue 5 years ago • 3 comments

I am using this package to loop through a number of reports for a regression test.

I have found that sometimes the package gets stuck on the line

var bytes = converter.FromUrl("url);

I am unable to debug any further when I stop the test the program then spits out the image with a random-guid.jpg (5fc03a58-304a-4f04-b4ab-f470ca29bac5.jpg), its strange as there is no error and I am unable to figure out what it's doing.

Is there some sort of memory/caching issue as I am trying to run through 100s of reports and it does not get to 40 before just stalling and doing nothing from what I can actually see.

Any ideas?

brianjmitchell avatar Feb 11 '20 16:02 brianjmitchell

Looks like its stuck on this lin in the FromURL method

process.WaitForExit();

the process is never updated that it's finished, it seems to do this on large HTML pages

brianjmitchell avatar Feb 12 '20 15:02 brianjmitchell

A colleague found this for me that might be of some help

https://csharp.today/how-to-avoid-deadlocks-when-reading-redirected-child-console-in-c/

    private static int BeParent()
    {
        var processInfo = new ProcessStartInfo
        {
            FileName = Environment.CommandLine.Replace(".vshost", string.Empty),
            Arguments = ChildParam,
            UseShellExecute = false,
            RedirectStandardOutput = true
        };

        using (var process = Process.Start(processInfo))
        {
            var output = process.StandardOutput.ReadToEnd();
            process.WaitForExit();

            Console.WriteLine("Child output: " + output);
        }

        return 0;
    } 

brianjmitchell avatar Feb 12 '20 15:02 brianjmitchell

Adding this line before the process.WaitForExit() string output = process.StandardError.ReadToEnd();

Fixed the issue I was having, I found that the HTML page I was trying to turn to an image had an embedded image from an https URL and an error was being thrown and never outputted which resulted in the application just waiting until it was stopped.

adding the line in outputted the error and carried.

brianjmitchell avatar Feb 12 '20 16:02 brianjmitchell