From 16c004d7b078da6f47db414e062019b24555d39f Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Thu, 22 Dec 2022 19:16:28 +0100 Subject: [PATCH] handle object disposed exception (#4221) Co-authored-by: Marco Rossignoli --- .../LengthPrefixCommunicationChannel.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs index b6ca3549e5..293a5a683b 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs @@ -111,9 +111,17 @@ public Task NotifyDataAvailable() /// public void Dispose() { - EqtTrace.Verbose("LengthPrefixCommunicationChannel.Dispose: Dispose reader and writer."); - _reader.Dispose(); - _writer.Dispose(); + try + { + EqtTrace.Verbose("LengthPrefixCommunicationChannel.Dispose: Dispose reader and writer."); + _reader.Dispose(); + _writer.Dispose(); + } + catch (ObjectDisposedException) + { + // We don't own the underlying stream lifecycle so it's possible that it's already disposed. + } + GC.SuppressFinalize(this); } }