Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (39 sloc) 2.09 KB
title ms.date ms.prod ms.technology ms.topic f1_keywords helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
CA2220: Finalizers should call base class finalizer | Microsoft Docs
11/15/2016
visual-studio-dev14
vs-ide-code-analysis
reference
CA2220
FinalizersShouldCallBaseClassFinalizer
CA2220
FinalizersShouldCallBaseClassFinalizer
48329f42-170d-45ee-a381-e33f55a240c5
16
jillre
jillfra
wpickett

CA2220: Finalizers should call base class finalizer

[!INCLUDEvs2017banner]

TypeName FinalizersShouldCallBaseClassFinalizer
CheckId CA2220
Category Microsoft.Usage
Breaking Change Non Breaking

Cause

A type that overrides xref:System.Object.Finalize%2A?displayProperty=fullName does not call the xref:System.Object.Finalize%2A method in its base class.

Rule Description

Finalization must be propagated through the inheritance hierarchy. To ensure this, types must call their base class xref:System.Object.Finalize%2A method from within their own xref:System.Object.Finalize%2A method. The C# compiler adds the call to the base class finalizer automatically.

How to Fix Violations

To fix a violation of this rule, call the base type's xref:System.Object.Finalize%2A method from your xref:System.Object.Finalize%2A method.

When to Suppress Warnings

Do not suppress a warning from this rule. Some compilers that target the common language runtime insert a call to the base type's finalizer into the Microsoft intermediate language (MSIL). If a warning from this rule is reported, your compiler does not insert the call, and you must add it to your code.

Example

The following Visual Basic example shows a type TypeB that correctly calls the xref:System.Object.Finalize%2A method in its base class.

[!code-vbFxCop.Usage.IDisposableBaseCalled#1]

See Also

Dispose Pattern

You can’t perform that action at this time.