IDISP024

November 25, 2021 ยท View on GitHub

Don't call GC.SuppressFinalize(this) when the type is sealed and has no finalizer

TopicValue
IdIDISP024
SeverityWarning
EnabledTrue
CategoryIDisposableAnalyzers.Correctness
CodeSuppressFinalizeAnalyzer

Description

Don't call GC.SuppressFinalize(this) when the type is sealed and has no finalizer.

Motivation

ADD MOTIVATION HERE

How to fix violations

ADD HOW TO FIX VIOLATIONS HERE

Configure severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#pragma warning disable IDISP024 // Don't call GC.SuppressFinalize(this) when the type is sealed and has no finalizer
Code violating the rule here
#pragma warning restore IDISP024 // Don't call GC.SuppressFinalize(this) when the type is sealed and has no finalizer

Or put this at the top of the file to disable all instances.

#pragma warning disable IDISP024 // Don't call GC.SuppressFinalize(this) when the type is sealed and has no finalizer

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness", 
    "IDISP024:Don't call GC.SuppressFinalize(this) when the type is sealed and has no finalizer", 
    Justification = "Reason...")]