O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

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

Serialize an Object to Disk

Problem

You need to persist a serializable object to a file and recreate it later.

Solution

Use .NET serialization with the help of BinaryFormatter or SoapFormatter.

Discussion

All serializable objects can be converted into a stream of bytes, and vice versa. To serialize an object manually, you need to use a class that supports IFormatter. The .NET Framework includes two: BinaryFormatter, which serializes an object to a compact binary representation, and SoapFormatter, which uses the SOAP XML format, and results in a longer text-based message. The BinaryFormatter class is found in the System.Runtime.Serialization.Formatters.Binary namespace, while SoapFormatter is found in the System.Runtime.Serialization.Formatters.Soap ...

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