Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Serializable, what and why?

0 views
Skip to first unread message

DBC User

unread,
May 1, 2006, 3:33:42 PM5/1/06
to
Could someone help me understand 'Serializable'?

What is this 'Serializable' why do we need it and how do we use it? Any
link or simple example would be great.

Nicholas Paldino [.NET/C# MVP]

unread,
May 1, 2006, 3:44:37 PM5/1/06
to
DBC User,

Serialization is the act of being able to take an instance of an object
and save it in its current state to another storage medium. In .NET, this
is always a stream, but since streams can have different backings, the uses
for this mechanism are virtually limitless.

One use is in remoting situations. When you pass parameters to/from a
method that is being executed in an app domain outside of your own,
serialization is used to package the parameters into byte streams that can
be passed to the other app domain.

You can also save the stream to a file on disk, or in a database, and
then deserialize the instance later, continuing to use it.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"DBC User" <dbc...@gmail.com> wrote in message
news:1146512022....@g10g2000cwb.googlegroups.com...

Greg Young

unread,
May 1, 2006, 3:44:09 PM5/1/06
to
http://msdn.microsoft.com/msdnmag/issues/02/04/net/ is probably a good
introduction.

Cheers,

Greg


"DBC User" <dbc...@gmail.com> wrote in message
news:1146512022....@g10g2000cwb.googlegroups.com...

Eric

unread,
May 1, 2006, 3:49:12 PM5/1/06
to
Serialization just means to store an object as a byte stream. It will
typically be an XML text byte stream, or a binary byte stream. You need
this functionality to store an object in a file, or to send it over a
wire. An object that is "serializable" meets the criteria for being
serialized automatically into XML (typically meaning it has public
read/write properties, at least one empty constructor overload, and
perhaps a few others). In order to be serialized as XML you will lose
the methods, of course. XML serialization is typically used for data
container classes and collections. Binary serialization can preserve
the methods and private members, but people normally don't speak in
terms of binary serialization.

DBC User

unread,
May 1, 2006, 3:53:16 PM5/1/06
to
Thanks a bunch guys. Greg, the link is very good.

Nicholas Paldino [.NET/C# MVP]

unread,
May 1, 2006, 4:12:43 PM5/1/06
to
Eric,

See inline:

> Serialization just means to store an object as a byte stream. It will
> typically be an XML text byte stream, or a binary byte stream.

A byte stream is a byte stream, there isn't a different flavor to either
of them. How they are interpreted is a different thing. The SOAP formatter
serializes instances into SOAP messages, which ultimately can be stored as a
byte stream, while the binary formatter uses a much more compact
representation.

> You need this functionality to store an object in a file, or to send it
> over a
> wire. An object that is "serializable" meets the criteria for being
> serialized automatically into XML (typically meaning it has public
> read/write properties, at least one empty constructor overload, and
> perhaps a few others).

It is eligible to be serialized using the SOAP formatter (which produces
XML), but it does not automatically mean that you can use XML serialization.

> In order to be serialized as XML you will lose the methods, of course.
> XML serialization is typically used for data container classes and
> collections.
> Binary serialization can preserve
> the methods and private members, but people normally don't speak in
> terms of binary serialization.

This isn't true. When you serialize an instance of a type, the method
information is not stored. That is a part of the type itself, and there is
no reason to store it. Rather, just the field values are stored. Storing
the method information would mean you are storing code in some way, or local
variables, and that's not what happens. It would make no sense to do so.

Eric

unread,
May 2, 2006, 8:47:21 PM5/2/06
to
When I was talking about binary serialization I was thinking of Marshal
By Value in remoting, in which a complete object (including methods) is
serialized and sent over the wire. I guess this isn't a generalized
case of using a Binary Formatter. I not exactly sure how this is done -
I haven't used it myself.

0 new messages