From 25e57e4a4c15513f505ea484237119b2a13b31a9 Mon Sep 17 00:00:00 2001 From: gabidabet <42586945+gabidabet@users.noreply.github.com> Date: Sun, 29 Sep 2024 16:57:02 +0100 Subject: [PATCH] Fix CA1816 warnings (#2317) Contributes to #1290. --- src/Polly/Bulkhead/AsyncBulkheadPolicy.cs | 2 ++ src/Polly/Bulkhead/BulkheadPolicy.cs | 2 ++ src/Polly/Polly.csproj | 2 +- src/Polly/Utilities/TimedLock.cs | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs b/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs index b0f787ea1df..cc1218ec7f7 100644 --- a/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs +++ b/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs @@ -60,6 +60,7 @@ public void Dispose() { _maxParallelizationSemaphore.Dispose(); _maxQueuedActionsSemaphore.Dispose(); + GC.SuppressFinalize(this); } } @@ -123,5 +124,6 @@ public void Dispose() { _maxParallelizationSemaphore.Dispose(); _maxQueuedActionsSemaphore.Dispose(); + GC.SuppressFinalize(this); } } diff --git a/src/Polly/Bulkhead/BulkheadPolicy.cs b/src/Polly/Bulkhead/BulkheadPolicy.cs index 68d257701b5..93f6ef060d1 100644 --- a/src/Polly/Bulkhead/BulkheadPolicy.cs +++ b/src/Polly/Bulkhead/BulkheadPolicy.cs @@ -58,6 +58,7 @@ public void Dispose() { _maxParallelizationSemaphore.Dispose(); _maxQueuedActionsSemaphore.Dispose(); + GC.SuppressFinalize(this); } } @@ -118,5 +119,6 @@ public void Dispose() { _maxParallelizationSemaphore.Dispose(); _maxQueuedActionsSemaphore.Dispose(); + GC.SuppressFinalize(this); } } diff --git a/src/Polly/Polly.csproj b/src/Polly/Polly.csproj index 98edd3925a1..088aa31f400 100644 --- a/src/Polly/Polly.csproj +++ b/src/Polly/Polly.csproj @@ -7,7 +7,7 @@ Library 70 true - $(NoWarn);CA1010;CA1031;CA1051;CA1063;CA1064;CA1724;CA1816; + $(NoWarn);CA1010;CA1031;CA1051;CA1063;CA1064;CA1724; $(NoWarn);S2223;S3215;S4039 $(NoWarn);RS0037; diff --git a/src/Polly/Utilities/TimedLock.cs b/src/Polly/Utilities/TimedLock.cs index 0bfb9bb177b..7b43a09c484 100644 --- a/src/Polly/Utilities/TimedLock.cs +++ b/src/Polly/Utilities/TimedLock.cs @@ -34,7 +34,9 @@ private static TimedLock Lock(object o, TimeSpan timeout) #if DEBUG #pragma warning disable S3234 // "GC.SuppressFinalize" should not be invoked for types without destructors #pragma warning disable S3971 // Do not call 'GC.SuppressFinalize' +#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize GC.SuppressFinalize(tl._leakDetector); +#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize #pragma warning restore S3971 #pragma warning restore S3234 #endif @@ -64,7 +66,9 @@ public void Dispose() // finalizer. #if DEBUG #pragma warning disable S3234 // "GC.SuppressFinalize" should not be invoked for types without destructors +#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize GC.SuppressFinalize(_leakDetector); +#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize #pragma warning restore S3234 #endif }