Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.65 KB

IDISP026.md

File metadata and controls

50 lines (36 loc) · 1.65 KB

IDISP026

Class with no virtual DisposeAsyncCore method should be sealed

Topic Value
Id IDISP026
Severity Warning
Enabled True
Category IDisposableAnalyzers.Correctness
Code ClassDeclarationAnalyzer

Description

Class with no virtual DisposeAsyncCore method should be sealed.

When implementing IAsyncDisposable, classes without a virtual DisposeAsyncCore method should be sealed. See https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-disposeasync.

How to fix violations

Mark classes the implement IAsyncDisposable as sealed.

Configure severity

Via ruleset file.

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

Via #pragma directive.

#pragma warning disable IDISP026 // Class with no virtual DisposeAsyncCore method should be sealed
Code violating the rule here
#pragma warning restore IDISP026 // Class with no virtual DisposeAsyncCore method should be sealed

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

#pragma warning disable IDISP026 // Class with no virtual DisposeAsyncCore method should be sealed

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness", 
    "IDISP026:Class with no virtual DisposeAsyncCore method should be sealed", 
    Justification = "Reason...")]