Sunday, March 4, 2012

Serialization/Deserialization in .NET

Serialization

Serialization is the process of taking an object and converting it to a format in which it can be transported across a network or persisted to a storage location. The storage location could be as simple as using a file or a database. The serialized format contains the object's state information.

Deserialization
Deserialization is the process of using the serialized state information to reconstruct the object from the serialized state to its original state.
 In essence, the process of serialization allows an object to be serialized, shipped across the network for remoting or persisted in a storage location such as the ASP.NET cache, and then be reconstructed for use at a later point in time.


Serialization Formats

There are three formats provided by the Microsoft .NET framework to which objects can be serialized. The formats are Binary, SOAP, and XML. The format is controlled based upon what object is used to perform the serialization. The XML format is produced by using the System.Xml.Serialization.XmlSerializer class. The SOAP and binary formats are produced by using classes under the System.Runtime.Serialization.Formatters namespace.
There are subtle differences among the serialized formats. The binary-based format is the most compact and light of the three formats. The XML formatter only serializes public fields and properties, while binary and SOAP do not adhere to that limitation.