CA1821 Remove Empty Finalizers

Why is VS complaining about this finalizer?

VS 2017 - 15.3.5
Microsoft Code Analysis 2017 - 2.3.0.62003

using System; namespace ConsoleApp { class DisposableClass : IDisposable { #if DEBUG ~DisposableClass () // CA1821 Remove empty Finalizers { System.Diagnostics.Debug.Fail ("Forgot Dispose?"); } #endif public void Dispose () { #if DEBUG GC.SuppressFinalize (this); #endif } } class Program { static void Main (string[] args) { Console.WriteLine ("Hello World!"); } } } 
+5
source share
1 answer

It looks like an error in the analyzer .

From the comment of June 23 in the issue:

@nguerrera Thank you, you are correct that the analyzer reports a valid release build problem. However, there is still a problem in the analyzer - it should not fire if the exclusive exclusive method is also excluded. For example, the following message still runs diagnostics in both release builds and debugging.

 #if DEBUG ~InvisibleEditor() { Debug.Assert(Environment.HasShutdownStarted, GetType().Name + " was leaked without Dispose being called."); } #endif 
+7
source

Source: https://habr.com/ru/post/1272732/


All Articles