CA2238: Implement serialization methods correctly
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
For the latest documentation on Visual Studio 2017, see CA2238: Implement serialization methods correctly on docs.microsoft.com.
| TypeName | ImplementSerializationMethodsCorrectly |
| CheckId | CA2238 |
| Category | Microsoft.Usage |
| Breaking Change | Breaking - If the method is visible outside the assembly. Non Breaking - If the method is not visible outside the assembly. |
A method that handles a serialization event does not have the correct signature, return type, or visibility.
A method is designated a serialization event handler by applying one of the following serialization event attributes:
Serialization event handlers take a single parameter of type System.Runtime.Serialization.StreamingContext, return void, and have private visibility.
To fix a violation of this rule, correct the signature, return type, or visibility of the serialization event handler.
Do not suppress a warning from this rule.
The following example shows correctly declared serialization event handlers.
CA2236: Call base class methods on ISerializable types
CA2240: Implement ISerializable correctly
CA2229: Implement serialization constructors
CA2235: Mark all non-serializable fields
CA2237: Mark ISerializable types with SerializableAttribute