diff --git a/src/Platform/Microsoft.Testing.Platform/IPC/NamedPipeClient.cs b/src/Platform/Microsoft.Testing.Platform/IPC/NamedPipeClient.cs index 658e6efb1..d49a7b9cf 100644 --- a/src/Platform/Microsoft.Testing.Platform/IPC/NamedPipeClient.cs +++ b/src/Platform/Microsoft.Testing.Platform/IPC/NamedPipeClient.cs @@ -202,21 +202,31 @@ internal sealed class NamedPipeClient : NamedPipeBase, IClient public void Dispose() { - if (!_disposed) + if (_disposed) { - _namedPipeClientStream.Dispose(); - _disposed = true; + return; } + + _lock.Dispose(); + _serializationBuffer.Dispose(); + _messageBuffer.Dispose(); + _namedPipeClientStream.Dispose(); + _disposed = true; } #if NETCOREAPP public async ValueTask DisposeAsync() { - if (!_disposed) + if (_disposed) { - await _namedPipeClientStream.DisposeAsync(); - _disposed = true; + return; } + + _lock.Dispose(); + await _serializationBuffer.DisposeAsync(); + await _messageBuffer.DisposeAsync(); + await _namedPipeClientStream.DisposeAsync(); + _disposed = true; } #endif }