public GoDocument TestSerialization()
SerializationException
s when debugging serialization errors such as during a copy-and-paste.public GoDocument TestSerialization()
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.
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; }