Introduction To Serialization In .NET


In the modern era of Computer Science, serialization and deserialization are very important topics and have gained merit with the passage of time. Since ancient times, human beings could communicate with each other and exchange messages in a secure way. Now, in this age, serialization comes before the communication layer used to convert one state or thing to another. When we have done an operation on a thing, the operation is referred to as "Serialization”.

Purpose of Serialization

In the modern era, an application does not consist of a single state; there are multiple states, either on the server-side, client-side, mobile-side, or even the embedded side so communication happens back and forth. Before the communication or storing something, we change the state of the information, keep things light, keep it more secure, and send over the medium named as Protocols in terms of the Computer Science. So, Serialization is the backbone of the real-time application to exchange the data back and forth. Today, I can say that almost 99.99 % application use Serialization/Deserialization for communication and to exchange the data keeping things light and secure.

Before Start

Well, when I prepared for my C# certification exam, I gave more time to study about serialization and understood how to implement it in the real-world applications. Also, I did learn what the natural flow is, what its benefits are, its disadvantages, and the different types of serialization. So now, I can teach about Serialization/Deserialization to the developers at beginner and intermediate level. This is the series of training lectures which imparts the details of Serialization/Deserialization.


Must have knowledge of System.IO namespace; not complete but a little knowledge of MemoryStream, Fieldstream, and some basic stream classes etc.

Now, let’s start.

My whole lectures are revolving around Serialization/Deserialization, streams, and some basic words so it’s better to get an overview of some theories and then, we will move towards the code and implementation. Well, personally, I don’t like words I like implantations so for me, I think it’s a boring kind of stuff but it is important to understand some basic terms which are the building block of Serialization/Deserialization.


Out of the box, “stream is the consecutive sequence of bytes which are used to read/write data to/from the storage medium in which the nature of the medium is independent”. In other words, we can say that byte array having some specific length is known as the stream, like we can say that cricket match is streaming. The online streaming carries the bytes of arrays of a stream.

Storage media

Storage media is a place where we store the data in the form of bytes like a file stream, Memory and sockets, XML, ZIP, JSON, JPEG and other memory sticks.

Object Graph

“Object Graph is referred to as an in-memory representation of the object."  How objects refer to each other” is known as the object graph. As we know that objects are stored in the heap memory having some reference, so in the heap memory, objects refer to each other. For example, we can say that a book object is having the reference to the page object and a Person object can have the reference of the book object. So, some connectivity between the objects is created which is known as an Object Graph.

  • Remember that the class structure “equals to” object graph,


This is the simple shape or example of the in-memory representation of the objects, which is known as an Object Graph.


In simple words, “Serialization is the process in which we convert the in-memory representation of the object named as Object Graph into a sequence of the bytes which can be persisted and transmitting over the media later.



The reverse process of the Serialization is known as Deserialization, i.e., converting the stream of bytes into object graph which is usable for the application. It has exact reverse steps of the serialization.

Media---------------> Bytes-------------> Deserialization-------> Object Graph-------->Application

Next, we will talk about the scenario where we use the Serialization in practice.


  • Windows backup, database backups, and software backups are the persistent implementations of the serialization; upon restore, the deserialization happens and we get the data.
  • When the application is sitting idle in the memory,  we serialize the state of the memory and store it in the physical media and utilize the memory. I found the example of that type in Microsoft BizTalk Server.
  • When we work with the web-based application, we have different types of variable application states - session states, and view states. Sometimes, we want to save the value data on the physical media which resides in these variable. There, we serialize it and save it.
  • Any kind of data which is stored on the physical media must pass through the process called Serialization.

  • In Windows, we know that different types of a processes work simultaneously. Sometimes, we want to communicate with the other process and, for that, we use the transmission mechanism of the serialization process.
  • Microsoft Communication Foundation framework extensively uses the Serialization process.
  • AJAX web request, Web API, Web Services extensively use the Serialization/Deserialization.

What’s Next

This is the introduction lecture only. In the next few lectures, we will talk about the types of Serialization in details with practice code.
We will discuss the advantages and disadvantages of each type of Serialization/Deserialization over other types.
Stay Tuned!