Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Implement serialization methods correctly







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.

using System;
using System.Runtime.Serialization;

namespace UsageLibrary
   public class SerializationEventHandlers
      void OnSerializing(StreamingContext context) {}

      void OnSerialized(StreamingContext context) {}

      void OnDeserializing(StreamingContext context) {}

      void OnDeserialized(StreamingContext context) {}

Community Additions

© 2015 Microsoft