What is serialization in C# ?

Serialization is the process of converting the state of objects into a stream of bytes that can be transported across a network or persisted in a storage location (memory/database/file).

Why is it used in .NET applications ?

Serialization is used when we must store data for later usage, such as archiving data. To transfer information from client to server, it should be serialized into a stream of bytes to transfer over the network.

Types of C# serialization

.NET offers three categories of serialization: 1.Binary serialization (light and compact in remote services). 2.XML serialization (custom serialization). SOAP serialization (used in web services). 3.Binary and SOAP are known as deep serializations, whereas XML is known as a shallow serialization.

Binary serialization

It can be used if you want your objects completely converted to bytes. All public and private members are serialized into bytes during binary serialization, including read-only members. It produces compact serializations using binary encoding for applications like storage or socket-based network streams.

XML serialization

It is the process of serializing an object's public fields and properties, or a method's arguments and return values, to XML or vice versa. It enables the conversion of XML documents and streams to common language runtime objects. Only an object's public properties and fields are serialized during the XML serialization process.

SOAP serialization

SOAP is an XML-based protocol created expressly to transport procedure calls. XmlSerializer can be used to serialize classes and produce encoded SOAP messages whereas a SOAP message is built using XML.

Advantages of C# serialization

Serialization lets you to store the persistent or non-persistent state of an object in a storage medium, allowing for the exact re-creation of that data later. This allows data to be transmitted across a network in a cross-platform compatible format.

2X faster app development !

Syncfusion offers over 1,800 components and frameworks for WinForms, WPF, ASP.NET (MVC, Core), UWP, WinUI, .NET MAUI, Xamarin, Flutter, Blazor, JavaScript, Angular, Vue, and React that make developers’ work easier.