In response to my article on Custom Binary Serialization in .NET, a visitor asked me for a specific example of a custom serialization class of .NET’s MailMessage class.
As I mentioned in the article, I struggled with the MailMessage and MailAddress class because they cannot be serialized unless you use custom serialization (which can be a big pain because it takes quite a bit of time to create a custom class). I spent days trying to serialize the MailMessage class using conventional methods, only to find that there is no quick workaround for it other than custom serialization.
In .NET, serialization is the process of converting a complex object into a bit stream or XML string, which can be saved into a file or sent over a network connection. Serialization is extensively used in web services to transfer information from client to server, and for saving .NET objects into an SQL database.
In this tutorial, I will show you how to implement binary serialization in .NET; you’ll quickly find that many objects in .NET are not natively serializable, so I’ll also show you how to customize an object to manually make it serializable.