O'Reilly logo

Object-Oriented Programming with Visual Basic .NET by J.P. Hamilton

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

8.3. Serialization

Reading and writing primitive data types to and from a stream is one thing, but what about objects? Converting an object to a stream is called serialization, and it is used for two primary purposes. The first is to persist an object to storage (such as a file) with the intent of recreating it later. The second is to send an object by value (marshal by value) to another computer or application domain. Serialization is necessary because an object is valid only within the application domain in which it was created. If the architecture demands that objects be shared or used in a distributed environment, then serialization is necessary. Serialization plays a major role in .NET remoting and, fortunately, the framework does most of the work.

When an object is serialized, the name of the assembly (this is the type boundary, after all), the class, and the member data are added to the stream. During this process, any referenced objects are serialized, too (if they are eligible). This is often called an object graph. Circular references are not a problem in the case of object graphs because the CLR keeps track of each serialized object to ensure that the object is not serialized more than once.

This chapter discusses two types of serialization:

  • Binary serialization

  • XML and SOAP serialization

Binary serialization maintains type integrity, which means that every aspect of the object is preserved, including private member data. Maintaining type integrity is useful in situations ...

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