All rules
CA2214Usage Enabled by default: No
Do not call overridable methods in constructors
Do not call overridable methods in constructors
Microsoft docsDescription
When a virtual method is called, the actual type that executes the method is not selected until runtime. When a constructor calls a virtual method, it's possible that the constructor for the instance that invokes the method has not executed. This could lead to errors or unexpected behavior, if an overridden virtual method relies on initialization and other configuration in the constructor.
Cause
The constructor of an unsealed type calls a virtual method defined in its class.
How to fix violations
To fix a violation of this rule, do not call a type's virtual methods from within the type's constructors.
When to suppress
Do not suppress a warning from this rule. The constructor should be redesigned to eliminate the call to the virtual method.
Your vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0