one major disadvantages with the binaryformatter is that you don't know what you have serialized

T

Tony Johansson

Hi!

You have three methods to use when serializing an object and these are:
1.BinaryFormatter
2.SoapFormatter
3.XML seializing

One major disadvantage with the BinaryFormatter is that you must document
exactly what you have serialize because if you don't you haven't the
slighest idea what you have serialized except text members.

If you use XML to serialize you can see exactly what you have serialize.
If you use XML to serialize insted of BinaryFormatter you will have much
greater files and the perfermance will be much slower then BinartFormatter.

So its probably best to use BinartFormatter what it's suitable and keep the
docs up to date.

I just wonder assume that you have serialized an object and you have forgot
what members you have serialized
is it any why to find out which members you have actually serialized ?

//Tony
 
P

Patrice

You serialize a class. The file contains the name of the class you
serialized as clear text. Additionally the SerializationBinder class allows
to get some info about the type being processed :
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.serializationbinder(VS.71).aspx

At some point your app has to know what to do i.e. it is unlikely you'll
serialize classes at random locations and then you'll try to restore from
files without knowing their content exacly as a db application will read a
particular table as needed and won't try to read the customer table when you
need to read from the invoice table.

Or you could take things the other way round and explain what you are trying
to do (you don"t ry to use serialized classes where a database would be the
way to go ?)
 
W

Willem van Rumpt

Tony said:
So its probably best to use BinartFormatter what it's suitable and keep the
docs up to date.

It's never "best" to just use the BinaryFormatter. What formatter you
need to use depends on the specifications. If you're serializing to send
an object to a third party consumer, it might be that the format has
already been decided for you. Otherwise, you can make your own
evaluations which one is to be preferred.
I just wonder assume that you have serialized an object and you have forgot
what members you have serialized
is it any why to find out which members you have actually serialized ?

Partially, by reconstructing the binary message through inspection,
reflection, investing lots of frustration, perspiration, cursing and
agony along the way, until you almost, but not completely, get it
completely wrong.

Of course, that's not the way to go.

If it's a .NET framework type you've serialized, you can assume that you
don't need to know what got serialized. Serialization - deserialization
cycles will just work.

If it's a type of your own that you're serializing, you can document
what gets serialized. Written documentation would be best. Lacking that,
the code will have to serve as documentation. Only version history from
a source control system could save you here, or implementing
ISerializable instead of the Serializable attribute, and build explicit
versioning into the class, so that the code for *all* versions will
always be there.

Versioning is hard to get right.
 
A

Arne Vajhøj

You serialize a class. The file contains the name of the class you
serialized as clear text.

I would phrase that as "You serialize an object. The file contains
the name of the class of the object you serialized as clear text".

Arne
 
A

Arne Vajhøj

You have three methods to use when serializing an object and these are:
1.BinaryFormatter
2.SoapFormatter
3.XML seializing

One major disadvantage with the BinaryFormatter is that you must document
exactly what you have serialize because if you don't you haven't the
slighest idea what you have serialized except text members.

The format of the binary formatter is given by the class
definition and the logic within the binary formatter.

If the other end has the same class definition and the same
binary formatter then they can read it.

If you use a custom serialization (BinaryReader/BinaryWriter), then
you need to document the protocol.
If you use XML to serialize you can see exactly what you have serialize.

Yes. And that is often convenient. If "something" happens.
If you use XML to serialize insted of BinaryFormatter you will have much
greater files and the perfermance will be much slower then BinartFormatter.
Yes.

I just wonder assume that you have serialized an object and you have forgot
what members you have serialized
is it any why to find out which members you have actually serialized ?

If you have lost the class definition then binary formatted
serialized data is for practically purposes lost (some forensics
can be done, but that is more art than technique).

Arne
 
A

Andy O'Neill

I just wonder assume that you have serialized an object and you have
forgot what members you have serialized
is it any why to find out which members you have actually serialized ?

What real world application do you envisage storing data and then you
randomly pick a bit of this data to turn into a class or something?

I would suggest Serialization is likely to be used for short term or low
priority storage.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top