Knowledge Base Article
Serialization is the process of converting an object or a graph of objects into
a contiguous stream of bytes.
Deserialization is the process of converting a contiguous stream of bytes back into
its graph of connected objects.
The ability to convert objects to and from a byte stream is an extremely useful
mechanism. For instance:
-
An application's state (object graph) can easily be saved in a disk file or database
and then restored the next time the application is run.
-
A set of objects can easily be copied to the system's clipboard and then pasted
into the same or another application.
-
A set of objects can be cloned and set aside as a backup while a user manipulates
the main set of objects.
-
A set of objects can easily be sent over the network to a process running on another
machine. The Microsoft® .NET Framework remoting and As Good As It Gets’ CF.Remoting
architecture serializes and deserializes objects that are marshaled by value.
In addition to these examples, once you have serialized objects in a byte stream
in memory, it is easy to perform some more useful operations on the data such as
encrypting and/or compressing the data.
Since serialization is so useful, many developers have spent countless hours developing
code to perform these types of actions. Historically, the serialization code is
difficult to write, extremely tedious, and error prone. Some of the difficult issues
that developers need to deal with are communication protocols, client/server data
type mismatches, such as little/big-endian conversions, error handling, objects
that refer to other objects, in and out parameters, arrays of structures.
You know that the full .NET Framework has fantastic support for serialization and
deserialization. You will be happy to know that CF.Serialization libraries bring
you the same support for the serialization and deserialization of the objects and
object graphs on the Microsoft .NET Compact Framework. This means that all of the
difficult issues mentioned before are now handled completely and transparently by
the CF.Serialization. The byte-stream produced by CF.Serialization is 100% compatible
with the byte-stream produced by the Microsoft’s BinaryFormatter. This means that
you can serialize your object on the Compact Framework and get this object read
on the full .NET framework and vise versa.
As a developer, you can work with your objects before serialization and after deserialization
and have CF.Serialization handle the stuff in the middle. For almost all data types,
the default behavior of provided services will be sufficient, meaning that it takes
almost no work for you to make your own types serializable.
Note: serialization/deserialization of the object graphs containing IntPtr is not
supported at this time due to bug in the Microsoft .NET Compact Framework runtime as outlined
here.