CA2238: Implement serialization methods correctly
Visual Studio 2010
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 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.
The following example shows correctly declared serialization event handlers.
using System; using System.Runtime.Serialization; namespace UsageLibrary { [SerializableAttribute] public class SerializationEventHandlers { [OnSerializingAttribute] void OnSerializing(StreamingContext context) {} [OnSerializedAttribute] void OnSerialized(StreamingContext context) {} [OnDeserializingAttribute] void OnDeserializing(StreamingContext context) {} [OnDeserializedAttribute] void OnDeserialized(StreamingContext context) {} } }