The .NET Framework includes extensive support for both serialization and deserialization, both from the perspective of clients wanting to serialize and deserialize objects, and from the perspective of types wanting some control over how and where they are serialized. This support is found in two sets of namespaces: System.Runtime.Serialization.* and System.Xml.Serialization.*.
Each of these namespaces includes a suite of types that, together with your types, form a serialization "engine," which has the ability to serialize one or more objects into a stream of some kind. Additionally, each of these namespaces supports XML as a serialization format (the System.Runtime.Serialization.* namespaces also support a binary serialization format).
The primary differences between the two serialization engines are that the one contained in the System.Runtime.Serialization.* namespaces supports arbitrary object graphs and can serialize any .NET type using SOAP Section 5 encoding. However, this engine produces XML that is very CLR-centric, describing primitive types using XML namespaces and schemas that assume the reader understands the CLR type system. On the other hand, the serialization engine contained in the System.Xml.Serialization.* namespaces produces very clean XSD schemas and matching XML instances, describing primitive types in terms of XSD data types wherever possible. However, it cannot handle arbitrary object graphs, and in some cases doesn't support all of the CLR paradigms naturally.
While both serialization engines fulfill valid (and different) needs, the rest of this chapter concentrates on the System.Runtime.Serialization.* serialization support because of its natural advantages for serializing the widest possible range of types in a CLR-centric manner.