From 670f8970615aca5af4b03ef280789e2bf5eab832 Mon Sep 17 00:00:00 2001 From: Krishna Yalavarthi Date: Thu, 22 Oct 2020 13:25:39 -0700 Subject: [PATCH 1/4] TranscriptionOption.Dispose() should be idempotent #13830 --- .../engine/hostifaces/MshHostUserInterface.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs index c4841cce94d..aaf52e561bb 100644 --- a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs @@ -1173,8 +1173,17 @@ public void Dispose() if (_contentWriter != null) { - _contentWriter.Flush(); - _contentWriter.Dispose(); + try + { + contentWriter.Flush(); + contentWriter.Dispose(); + } + catch (ObjectDisposedException) + { + } + catch(IOException) + { + } _contentWriter = null; } From 4816f97f05e5d3e98690d3a056a985d0e3860bce Mon Sep 17 00:00:00 2001 From: Krishna Yalavarthi Date: Thu, 22 Oct 2020 13:27:35 -0700 Subject: [PATCH 2/4] TranscriptionOption.Dispose() should be idempotent #13830 --- .../engine/hostifaces/MshHostUserInterface.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs index aaf52e561bb..2b8ca8a3a1e 100644 --- a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs @@ -1175,8 +1175,8 @@ public void Dispose() { try { - contentWriter.Flush(); - contentWriter.Dispose(); + _contentWriter.Flush(); + _contentWriter.Dispose(); } catch (ObjectDisposedException) { From 237fe97a2364be5cfd36f2a439b0576c99506db0 Mon Sep 17 00:00:00 2001 From: Krishna Yalavarthi Date: Thu, 22 Oct 2020 14:28:46 -0700 Subject: [PATCH 3/4] TranscriptionOption.Dispose() - formatting --- .../engine/hostifaces/MshHostUserInterface.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs index 2b8ca8a3a1e..776aa302a2c 100644 --- a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs @@ -1180,9 +1180,11 @@ public void Dispose() } catch (ObjectDisposedException) { + // Do nothing } - catch(IOException) + catch (IOException) { + // Do nothing } _contentWriter = null; } From 1030517f5f7b7a4be301966232aabacc4486ab01 Mon Sep 17 00:00:00 2001 From: Krishna Yalavarthi Date: Thu, 22 Oct 2020 14:30:39 -0700 Subject: [PATCH 4/4] TranscriptionOption.Dispose() - formatting --- .../engine/hostifaces/MshHostUserInterface.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs index 776aa302a2c..09d4d9a9075 100644 --- a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs @@ -1186,6 +1186,7 @@ public void Dispose() { // Do nothing } + _contentWriter = null; }