Mark ISerializable types with SerializableAttribute
Mark ISerializable types with SerializableAttribute
Microsoft docsDescription
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 CA2237When to suppress
Do not suppress a warning from this rule for exception classes, because they must be serializable to work correctly across application domains.