All rules
CA2237Usage Enabled by default: No

Mark ISerializable types with SerializableAttribute

Mark ISerializable types with SerializableAttribute

Microsoft docs

Description

To be recognized by the common language runtime as serializable, types must be marked with the System.SerializableAttribute attribute even if the type uses a custom serialization routine through implementation of the System.Runtime.Serialization.ISerializable interface.

Cause

An externally visible type implements the System.Runtime.Serialization.ISerializable interface and the type is not marked with the System.SerializableAttribute attribute. The rule ignores derived types whose base type is not serializable.

How to fix violations

To fix a violation of this rule, apply the System.SerializableAttribute attribute to the type.

Example

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

When to suppress

Do not suppress a warning from this rule for exception classes, because they must be serializable to work correctly across application domains.

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