From 9a79ec280159d935c8607fc9433cd3fa9bee7ac6 Mon Sep 17 00:00:00 2001 From: John Salem Date: Mon, 19 Jul 2021 17:02:59 -0700 Subject: [PATCH] Fix fallback for resumeruntime (#2441) * Fix fallback for resumeruntime * Throw unsupported exception and catch everywhere it is used. --- .../DiagnosticsClient/DiagnosticsClient.cs | 6 +++++- src/Tools/dotnet-counters/CounterMonitor.cs | 9 ++++++++- .../dotnet-trace/CommandLine/Commands/CollectCommand.cs | 9 ++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs index 95aeac52d..62391f376 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs @@ -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; diff --git a/src/Tools/dotnet-counters/CounterMonitor.cs b/src/Tools/dotnet-counters/CounterMonitor.cs index bd12f08dc..9f1ba309f 100644 --- a/src/Tools/dotnet-counters/CounterMonitor.cs +++ b/src/Tools/dotnet-counters/CounterMonitor.cs @@ -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; diff --git a/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs b/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs index 9ed10bc21..f9d191e4e 100644 --- a/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs +++ b/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs @@ -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) -- 2.34.1