troubleshooting Question

ASP.NET gets InvalidOperationException exception on System.Diagnostic.Process object

Avatar of Member_2_8198376
Member_2_8198376 asked on
C#ASP.NETMicrosoft Visual Studio
8 Comments1 Solution657 ViewsLast Modified:
I have an ASP.NET MVC Framework application in C#. In one of my Controller functions, I get the following errors:
BasePriority = 'process.BasePriority' threw an exception of type 'System.InvalidOperationException'
HandleCount = 'process.HandleCount' threw an exception of type 'System.InvalidOperationException'
MainModule = 'process.MainModule' threw an exception of type 'System.ComponentModel.Win32Exception'
MainWindowHandle = 'process.MainWindowHandle' threw an exception of type 'System.InvalidOperationException'
Modules = 'process.Modules' threw an exception of type 'System.ComponentModel.Win32Exception'
ProcessName = 'process.ProcessName' threw an exception of type 'System.InvalidOperationException'
Position = '((System.IO.FileStream)process.StandardError.BaseStream).Position' threw an exception of type 'System.NotSupportedException'
Threads = 'process.Threads' threw an exception of type 'System.InvalidOperationException'

There are other errors also, Most of them are InvalidOperationException errors.

Here is the code.
[AllowAnonymous]
public ActionResult PrintSummaryPDF()
{
    Process process = null;
    ProcessStartInfo processStartInfo = new ProcessStartInfo();
    processStartInfo.FileName = ConfigurationManager.AppSettings["WkHtmlToPdfExePath"];
    processStartInfo.Verb = "runas";
    processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    processStartInfo.RedirectStandardError = true;
    processStartInfo.RedirectStandardOutput = true;
    processStartInfo.CreateNoWindow = true;
    processStartInfo.UseShellExecute = false;
    string fileNameDatePart = DateTime.Now.ToLongTimeString().Replace(":", string.Empty).Replace(" ", string.Empty);
    string pdfFileName = "Survey" + fileNameDatePart + ".pdf";
    processStartInfo.Arguments = HttpContext.Request.Url.AbsoluteUri.Replace("PrintSummaryPDF", "PrintSummary") + " " +
        " --load-error-handling ignore" + " --cookie .ASPXAUTH " + Request.Cookies["DCCCDCookie"].Value + " \"" + ConfigurationManager.AppSettings["WkHtmlToPdfOutputPath"] + pdfFileName + "\"";
    process = Process.Start(processStartInfo);
    process.WaitForExit(Convert.ToInt32(ConfigurationManager.AppSettings["TimeOut"]));

    int exitCode = process.ExitCode;
    string stdout = process.StandardOutput.ReadToEnd();
    string stderr = process.StandardError.ReadToEnd();

    return File("../pdfoutput/" + pdfFileName, "application/pdf");
}

The browser page then states:
Can’t reach this page
•Make sure the web address http://localhost:54635 is correct

The StandardOutput, stdout, reads:

Qt: Untested Windows version 6.2 detected!
Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[================>                                           ] 27%
[===================>                                        ] 33%
[=======================>                                    ] 39%
[============================>                               ] 47%
[=====================================>                      ] 62%
[========================================>                   ] 68%
[============================================>               ] 74%
[================================================>           ] 81%
[============================================================] 100%
Counting pages (2/6)                                               
[============================================================] Object 1 of 1
Resolving links (4/6)                                                       
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                           
Printing pages (6/6)
[>                                                           ] Preparing
[==============================>                             ] Page 1 of 2
[============================================================] Page 2 of 2
Done    

I suspected that the path to, WkHtmlToPdfExePath perhaps did not have sufficient permissions for iisexpress.exe; but when I check the permissions, it has full permissions for my account and the admin account, and I do have admin privileges on this machine.
I also checked the, WkHtmlToPdfOutputPath

This application is running in Visual Studio Enterprise 2017, version 15.8.7

Please advise. Thanks.
ASKER CERTIFIED SOLUTION
Member_2_8198376

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros