From 8617363089a779350a708ea031ab28e19397f11c Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 20 Feb 2019 23:55:39 -0800 Subject: [PATCH] Use the OperationCancellationException to replace the StoppingException in 'ConvertToJson' (#8920) --- .../commands/utility/WebCmdlet/JsonObject.cs | 14 ++------------ .../engine/serialization.cs | 1 + 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs index 0c80e98082..5a3552f534 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs @@ -104,13 +104,6 @@ namespace Microsoft.PowerShell.Commands } } - /// - /// Exception used for cancellation. - /// - private class StoppingException : System.Exception - { - } - #endregion HelperTypes #region ConvertFromJson @@ -483,7 +476,7 @@ namespace Microsoft.PowerShell.Commands return JsonConvert.SerializeObject(preprocessedObject, jsonSettings); } - catch (StoppingException) + catch (OperationCanceledException) { return null; } @@ -500,10 +493,7 @@ namespace Microsoft.PowerShell.Commands /// An object suitable for serializing to JSON. private static object ProcessValue(object obj, int currentDepth, in ConvertToJsonContext context) { - if (context.CancellationToken.IsCancellationRequested) - { - throw new StoppingException(); - } + context.CancellationToken.ThrowIfCancellationRequested(); PSObject pso = obj as PSObject; diff --git a/src/System.Management.Automation/engine/serialization.cs b/src/System.Management.Automation/engine/serialization.cs index 184ef6a1f8..b69f2434f4 100644 --- a/src/System.Management.Automation/engine/serialization.cs +++ b/src/System.Management.Automation/engine/serialization.cs @@ -6714,6 +6714,7 @@ namespace Microsoft.PowerShell null, ExtendedTypeSystem.InvalidCastException, sourceValue, + typeof(PSObject), destinationType); }