All rules
CA2216Usage Enabled by default: No
Disposable types should declare finalizer
Disposable types should declare finalizer
Microsoft docsDescription
A violation of this rule is reported if the disposable type contains fields of the following types:
- System.IntPtr
- System.UIntPtr
- System.Runtime.InteropServices.HandleRef
Cause
A type that implements System.IDisposable, and has fields that suggest the use of unmanaged resources, does not implement a finalizer as described by System.Object.Finalize.
How to fix violations
To fix a violation of this rule, implement a finalizer that calls your System.IDisposable.Dispose method.
Example
#pragma warning disable CA2216
// The code that's violating the rule is on this line.
#pragma warning restore CA2216When to suppress
It is safe to suppress a warning from this rule if the type does not implement System.IDisposable for the purpose of releasing unmanaged resources.
Your vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0