O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Serialization Support in the Framework

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required