Fix a NullRefException by finished process (#2338)
authorSung Yoon Whang <suwhang@microsoft.com>
Sun, 6 Jun 2021 03:35:12 +0000 (20:35 -0700)
committerGitHub <noreply@github.com>
Sun, 6 Jun 2021 03:35:12 +0000 (20:35 -0700)
src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs

index 14c66b3fc0d9d625b01aedcb1413f496afcbdf18..3764b1da9f57328b69d013d66877315430bb7421 100644 (file)
@@ -312,7 +312,7 @@ namespace Microsoft.Diagnostics.Tools.Trace
                         // If the process is shutting down by itself print the return code from the process.
                         // Capture this before leaving the using, as the Dispose of the DiagnosticsClientHolder
                         // may terminate the target process causing it to have the wrong error code
-                        if (ProcessLauncher.Launcher.ChildProc.WaitForExit(5000))
+                        if (ProcessLauncher.Launcher.HasChildProc && ProcessLauncher.Launcher.ChildProc.WaitForExit(5000))
                         {
                             ret = ProcessLauncher.Launcher.ChildProc.ExitCode;
                             Console.WriteLine($"Process exited with code '{ret}'.");