Fix fallback for resumeruntime (#2441)
authorJohn Salem <josalem@microsoft.com>
Tue, 20 Jul 2021 00:02:59 +0000 (17:02 -0700)
committerGitHub <noreply@github.com>
Tue, 20 Jul 2021 00:02:59 +0000 (17:02 -0700)
* Fix fallback for resumeruntime
* Throw unsupported exception and catch everywhere it is used.

src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs
src/Tools/dotnet-counters/CounterMonitor.cs
src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs

index 95aeac52d7ae58746c7249f680c06ec703dd1ed0..62391f376a95f3a9e1ac22eac0d7a787c5967383 100644 (file)
@@ -313,7 +313,11 @@ namespace Microsoft.Diagnostics.NETCore.Client
             switch ((DiagnosticsServerResponseId)response.Header.CommandId)
             {
                 case DiagnosticsServerResponseId.Error:
-                    var hr = BitConverter.ToInt32(response.Payload, 0);
+                    var hr = BitConverter.ToUInt32(response.Payload, 0);
+                    if (hr == (uint)DiagnosticsIpcError.UnknownCommand)
+                    {
+                        throw new UnsupportedCommandException($"Resume runtime command is unknown by target runtime.");
+                    }
                     throw new ServerErrorException($"Resume runtime failed (HRESULT: 0x{hr:X8})");
                 case DiagnosticsServerResponseId.OK:
                     return;
index bd12f08dc3f51bdf93d454c900bf956e887d2512..9f1ba309fca42b6534b5db688b475a106d73fe5c 100644 (file)
@@ -343,7 +343,14 @@ namespace Microsoft.Diagnostics.Tools.Counters
                     _session = _diagnosticsClient.StartEventPipeSession(Trace.Extensions.ToProviders(providerString), false, 10);
                     if (_resumeRuntime)
                     {
-                        _diagnosticsClient.ResumeRuntime();
+                        try
+                        {
+                            _diagnosticsClient.ResumeRuntime();
+                        }
+                        catch (UnsupportedCommandException)
+                        {
+                            // Noop if the command is unknown since the target process is most likely a 3.1 app.
+                        }
                     }
                     var source = new EventPipeEventSource(_session.EventStream);
                     source.Dynamic.All += DynamicAllMonitor;
index 9ed10bc21dc6fa47961f7d3c27bdeae27b987044..f9d191e4e3a1bbc037a90f65d399a6e2998d5d67 100644 (file)
@@ -222,7 +222,14 @@ namespace Microsoft.Diagnostics.Tools.Trace
                             session = diagnosticsClient.StartEventPipeSession(providerCollection, true, (int)buffersize);
                             if (resumeRuntime)
                             {
-                                diagnosticsClient.ResumeRuntime();
+                                try
+                                {
+                                    diagnosticsClient.ResumeRuntime();
+                                }
+                                catch (UnsupportedCommandException)
+                                {
+                                    // Noop if command is unsupported, since the target is most likely a 3.1 app.
+                                }
                             }
                         }
                         catch (DiagnosticsClientException e)