Northwoods.Go Assembly > Northwoods.Go Namespace > GoDocument Class : TestSerialization Method |
SerializationException
s when debugging serialization errors such as during a copy-and-paste.'Declaration Public Function TestSerialization() As GoDocument
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
.
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; }
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.
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2