GoDigram for .NET Framework and .NET Core
Northwoods.Go Namespace / GoDocument Class / TestSerialization Method
Example
In This Topic
    TestSerialization Method
    In This Topic
    Test serializing and deserializing this document, to help discover unserializable objects by getting SerializationExceptions when debugging serialization errors such as during a copy-and-paste.
    Syntax
    public GoDocument TestSerialization()

    Return Value

    a copy of this document, including all of its contents and any referenced objects
    Remarks

    Serialization of a GoDocument and its GoObjects is important for copy-and-paste and drag-and-drop (in Windows Forms) and for session state (in ASP.NET Web Forms). Sometimes copy-and-paste will result in missing objects, due to unserializable objects or serialization errors.

    You can call this method to help debug serialization problems. This method serializes this document into a MemoryStream and then immediately deserializes it back into a newly copied document. If there is a problem, you are likely to get a SerializationException, which should give you a clue as to which class needs to be attributed Serializable or which fields need to be attributed NonSerialized. Because this may consume significant time and space without actually changing anything, do not call this method in a production environment except when investigating a serialization problem.

    Example
    This method is implemented as:
    public GoDocument TestSerialization() {
      MemoryStream memstream = new MemoryStream();
      IFormatter oformatter = new BinaryFormatter();
      oformatter.Serialize(memstream, this);
      memstream.Position = 0;
      IFormatter iformatter = new BinaryFormatter();
      return iformatter.Deserialize(memstream) as GoDocument;
    }
    See Also