From: John Salem Date: Tue, 20 Jul 2021 00:02:59 +0000 (-0700) Subject: Fix fallback for resumeruntime (#2441) X-Git-Tag: submit/tizen/20220302.040122~25^2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9a79ec280159d935c8607fc9433cd3fa9bee7ac6;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Fix fallback for resumeruntime (#2441) * Fix fallback for resumeruntime * Throw unsupported exception and catch everywhere it is used. --- 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)