Search code examples
c#asp.netasp.net-mvcgoogle-chromepdf

Process.Start(...) Suddenly Fails when Called by ASP.NET MVC 5 Running in IIS on Windows 10 and Windows Server 2019


I have a sudden issue that I can't seem to grasp. In my ASP.NET MVC 5 (.NET Framework 4.8) app running on IIS on Windows 10 (dev), and Windows Server 2019 (prod), I have had the following code to generate PDFs from HTML rendered on the server and saved as a file using Google Chrome.

Process.Start("cmd.exe", "/C \"\"C:/Program Files/Google/Chrome/Application/chrome.exe\" --headless --disable-gpu --run-all-compositor-stages-before-draw --no-margins --no-pdf-header-footer --print-to-pdf=E:\\Chrome-Print-to-PDF\\e24cfc08-f91f-46ec-82be-85f49f1178f6.pdf E:\\Chrome-Print-to-PDF\\e24cfc08-f91f-46ec-82be-85f49f1178f6.html\"");

This has worked for 2, maybe 3 years now. This worked yesterday. As of today it fails inexplicably without any errors at all. It just simply does not generate the PDF. The Chrome-Print-to-PDF folder on both machines has Everyone with full permissions set, so I don't think it's a permission issue.

Running that code in LINQPad 5 generates the PDF as expected.

Running the command like this in Command Prompt also works:

CMD.EXE /C ""C:/Program Files/Google/Chrome/Application/chrome.exe" --headless --disable-gpu --run-all-compositor-stages-before-draw --no-margins --no-pdf-header-footer --print-to-pdf=E:\Chrome-Print-to-PDF\e24cfc08-f91f-46ec-82be-85f49f1178f6.pdf E:\Chrome-Print-to-PDF\e24cfc08-f91f-46ec-82be-85f49f1178f6.html"

Or like this, also in Command Prompt works:

CMD.EXE "C:/Program Files/Google/Chrome/Application/chrome.exe" --headless --disable-gpu --run-all-compositor-stages-before-draw --no-margins --no-pdf-header-footer --print-to-pdf=E:\Chrome-Print-to-PDF\e24cfc08-f91f-46ec-82be-85f49f1178f6.pdf E:\Chrome-Print-to-PDF\e24cfc08-f91f-46ec-82be-85f49f1178f6.html

I am at a complete loss what to do to resolve this within my ASP.NET MVC 5 app running in IIS. I am desperately looking for any help because this has blocked my app from generating any PDFs and I have many users hounding me.


Solution

  • The comments and links from @KJ got me to a solution. And to answer @KJ, yes, it did update to 128. The command changed to:

    Process.Start("cmd.exe", "/C \"\"C:/Program Files/Google/Chrome/Application/chrome.exe\" --headless=old --run-all-compositor-stages-before-draw --no-pdf-header-footer --print-to-pdf=E:\\Chrome-Print-to-PDF\\e24cfc08-f91f-46ec-82be-85f49f1178f6.pdf E:\\Chrome-Print-to-PDF\\e24cfc08-f91f-46ec-82be-85f49f1178f6.html\"");
    

    This now works. The problem is --headless=old. Eventually the old version will be removed, but I can't get the new version to work either, so looks like in due time we'll be back on SO for that issue. Hopefully the bugs related to this address that and we can use the new version the way we were using the old version.

    @ItAllMakesSense, I did see that answer and implemented it to see the output, but it didn't really help much.

    @Charlieface, you got me on that one, I guess at the time I just called it good and moved on after however long it took me to get it working. That being said, you are right, and I have updated the command to use Chrome directly rather than going through CMD:

    Process.Start("C:/Program Files/Google/Chrome/Application/chrome.exe", "--headless=old --run-all-compositor-stages-before-draw --no-pdf-header-footer --print-to-pdf=E:\\Chrome-Print-to-PDF\\e24cfc08-f91f-46ec-82be-85f49f1178f6.pdf E:\\Chrome-Print-to-PDF\\e24cfc08-f91f-46ec-82be-85f49f1178f6.html");
    

    Thank you all for the help! Until we meet again when --headless=old stops working!