All rules
CA1033Design Enabled by default: No

Interface methods should be callable by child types

Interface methods should be callable by child types

Microsoft docs

Description

Consider a base type that explicitly implements a public interface method. A type that derives from the base type can access the inherited interface method only through a reference to the current instance (this in C#) that is cast to the interface. If the derived type reimplements (explicitly) the inherited interface method, the base implementation can no longer be accessed. The call through the current instance reference will invoke the derived implementation; this causes recursion and an eventual stack overflow.

This rule does not report a violation for an explicit implementation of System.IDisposable.Dispose when an externally visible Close() or System.IDisposable.Dispose(Boolean) method is provided.

Cause

An unsealed externally visible type provides an explicit method implementation of a public interface and does not provide an alternative externally visible method that has the same name.

How to fix violations

To fix a violation of this rule, implement a new method that exposes the same functionality and is visible to derived types or change to a nonexplicit implementation. If a breaking change is acceptable, an alternative is to make the type sealed.

Example

#pragma warning disable CA1033
// The code that's violating the rule is on this line.
#pragma warning restore CA1033

When to suppress

It is safe to suppress a warning from this rule if an externally visible method is provided that has the same functionality but a different name than the explicitly implemented method.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0