We recommend using Visual Studio 2017

CA1048: Do not declare virtual members in sealed types


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CA1048: Do not declare virtual members in sealed types.

|Breaking Change|Breaking|

A public type is sealed and declares a method that is both virtual (Overridable in Visual Basic) and not final. This rule does not report violations for delegate types, which must follow this pattern.

Types declare methods as virtual so that inheriting types can override the implementation of the virtual method. By definition, you cannot inherit from a sealed type, making a virtual method on a sealed type meaningless.

The Visual Basic .NET and C# compilers do not allow types to violate this rule.

To fix a violation of this rule, make the method non-virtual or make the type inheritable.

Do not suppress a warning from this rule. Leaving the type in its current state can cause maintenance issues and does not provide any benefits.

The following example shows a type that violates this rule.

using namespace System;

namespace DesignLibrary
    public ref class SomeType sealed
        virtual bool VirtualFunction() { return true; }