Search code examples
c#visual-studio-2012visual-studio-debuggingjitprocess.start

Disable JIT debugging


This topic has been asked and answered in many questions and I did my due diligence but I just can't figure out why I am having the issue I have.

In testfailure.exe:

namespace testfailture
{
 class Program
  {
    static void Main(string[] args)
  {
       try
      {
          throw new Exception("I want to report this in the parent window");
      }
      catch (Exception ex)
      {
          throw ex;
      }
   }
}

In test.exe:

internal void Execute(string packageVersion)
 {

    Process exeProcess = new Process();   
    exeProcess.StartInfo.FileName = "testfailure.exe";
    exeProcess.StartInfo.RedirectStandardOutput = true;
    exeProcess.StartInfo.UseShellExecute = false;
    exeProcess.StartInfo.CreateNoWindow = true;

    try
    {
        exeProcess.Start();
        Console.WriteLine(exeProcess.StandardOutput.ReadToEnd());

    }
    catch (Exception ex)
    {
        throw ex;
    }
}

When I run the program, I get the pop-up and wouldn't let the program proceed until an action is taken.

enter image description here

I thought this was due to JIT debugging so I did everything from: https://social.msdn.microsoft.com/Forums/vstudio/en-US/a52eb0ae-bcd8-4043-9661-d5fc3aa5167c/getting-rid-of-justintime-debugger?forum=vsdebug

That is one problem I have but ultimate what I want to do is subprocess reporting back the error (not console.writeline because I want to use that for reporting status) to the parent and display in parent's window.

Any thoughts?

By the way, I am using Visual Studio Professional 2012. Your help is much appreciated.

Thanks!

Edit #1----------------------------

My process fully expects everything to work but what I am trying to do is to code for unexpected failures. When fails, I want to have a good dialogue so I can easily and quickly detect and debug.


Solution

  • Throwing an unhandled exception cannot be passed to a parent process.

    What you CAN do, however, is to write data to StandardError, and capture that in the parent process.

    The example below is from MSDN:

        Public Sub Main()
          Dim args() As String = Environment.GetCommandLineArgs()
          Dim errorOutput As String = "" 
          ' Make sure that there is at least one command line argument. 
          If args.Length <= 1 Then
             errorOutput += "You must include a filename on the command line." +
                            vbCrLf
          End If 
    
          For ctr As Integer = 1 To args.GetUpperBound(0)
             ' Check whether the file exists. 
             If Not File.Exists(args(ctr)) Then
                errorOutput += String.Format("'{0}' does not exist.{1}",
                                             args(ctr), vbCrLf)
             Else 
                ' Display the contents of the file. 
                Dim sr As New StreamReader(args(ctr))
                Dim contents As String = sr.ReadToEnd()
                sr.Close()
                Console.WriteLine("***** Contents of file '{0}':{1}{1}",
                                  args(ctr), vbCrLf)
                Console.WriteLine(contents)
                Console.WriteLine("*****{0}", vbCrLf)
             End If 
          Next 
    
          ' Check for error conditions. 
          If Not String.IsNullOrEmpty(errorOutput) Then 
             ' Write error information to a file.
             Console.SetError(New StreamWriter(".\ViewTextFile.Err.txt"))
             Console.Error.WriteLine(errorOutput)
             Console.Error.Close()
             ' Reacquire the standard error stream. 
             Dim standardError As New StreamWriter(Console.OpenStandardError())
             standardError.AutoFlush = True
             Console.SetError(standardError)
             Console.Error.WriteLine("{0}Error information written to ViewTextFile.Err.txt",
                                     vbCrLf)
          End If 
       End Sub