473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

BinaryFormatter Serialization format? Is it documented?


I have a custom set of objects that is correctly serializing &
deserializing the object tree. However in some cases the size of the
resultant serialization is larger than I would expect. Is there any
documented way to pull apart the stream to determine the sizes of the
objects embedded within the file? For example if I open the file up in
a Hex editor the 'containing' format looks reasonably simple to
decode, but I would rather be coding business logic rather than
figuring out a custom file format! Is the format documented (or
accessible via API)?

What I am looking for is a way to see all the of the named of the
serialized object within a stream with a count of the instances and
number of bytes taken up by the serialization.

Is there a mechanism or tool to do this?

Many thanks,

Gareth

May 1 '07 #1
5 6694
Gareth,

I doubt there is, as the document isn't formatted.

Because it isn't formatted, I have to wonder how you are formulating the
idea that the serialized instance is larger than you expect. There is
nothing to base that idea on.

How big are the files, and what is the size that you are expecting them
to be? Also, is the file size really causing that much of a problem?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<go**************@theisaacfamily.co.ukwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
>
I have a custom set of objects that is correctly serializing &
deserializing the object tree. However in some cases the size of the
resultant serialization is larger than I would expect. Is there any
documented way to pull apart the stream to determine the sizes of the
objects embedded within the file? For example if I open the file up in
a Hex editor the 'containing' format looks reasonably simple to
decode, but I would rather be coding business logic rather than
figuring out a custom file format! Is the format documented (or
accessible via API)?

What I am looking for is a way to see all the of the named of the
serialized object within a stream with a count of the instances and
number of bytes taken up by the serialization.

Is there a mechanism or tool to do this?

Many thanks,

Gareth

May 1 '07 #2
Firstly thanks for the reply!

It is the size is bigger than I expected because there is (I am
assuming) a rogue object that is keeping a reference to a contained
object that it shouldn't (if I serialize the same object tree twice
after significant processing the second serialization is larger than
the first). As such the serialization is actually pulling in too much
information (and so the larger size) - not a serialization bug, but an
implementation bug in one of the objects keeping a rogue pointer (or
so I suspect). Unfortunately due to the fact that the objects can be
dynamically added to the graph via a plugin architecture (and the
objects persist their own state) it is hard to determine where the
delta data size is coming from.

The best 'documentation' I've found is located
http://primates.ximian.com/~lluis/di...ion_format.htm
.. It appears however that the sscli20 has the implementation code for
the formatters so I could probably work it out from there - but that
is not something on my fun to do list!

The format is 'formatted', but just not in a human readable manner.
The deserialization knows how to read it, and reconstitute the
encapsulated objects. I'm only looking for the size of the objects :-)

So unless someone has written a 'summarization' reader of
binaryformatted to determine sizes and graphs of the data, and there
isnt a API to get the size of the individual data elements within the
stream I'll have to either write one - or poke around with notepad to
see what is being persisted and shouldn't be!!

On May 1, 9:09 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Gareth,

I doubt there is, as the document isn't formatted.

Because it isn't formatted, I have to wonder how you are formulating the
idea that the serialized instance is larger than you expect. There is
nothing to base that idea on.

How big are the files, and what is the size that you are expecting them
to be? Also, is the file size really causing that much of a problem?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
May 1 '07 #3
Well, if you are not in control of the plug ins, then there is little
you can do. If the plug ins are under your control, then the same
techniques you apply to the main object being serialized can be applied to
the objects attached to the graph by the plug ins.

The very first thing I would look at is to make sure you are not
serializing any delegate chains to the graph. Delegates will end up
serializing every object that they hold a reference to (assuming that you
are holding a delegate to an instance method), and that could easily add the
overhead you are seeing if you have objects subscribing to events that the
serialized object is exposing.

The easy way to get around this is to mark the events with NonSerialized
attribute, using the field indicator, like so:

[field:NonSerialized]
public event EventHandler MyEvent;

That should keep your events from not being serialized (assuming this is
the case in the first place).

If it is not, to be honest, I would just look at the object tree in the
debugger at the point before you serialize. You should be able to easily
determine (with enough digging) which objects are necessary and which are
not.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<go**************@theisaacfamily.co.ukwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...
Firstly thanks for the reply!

It is the size is bigger than I expected because there is (I am
assuming) a rogue object that is keeping a reference to a contained
object that it shouldn't (if I serialize the same object tree twice
after significant processing the second serialization is larger than
the first). As such the serialization is actually pulling in too much
information (and so the larger size) - not a serialization bug, but an
implementation bug in one of the objects keeping a rogue pointer (or
so I suspect). Unfortunately due to the fact that the objects can be
dynamically added to the graph via a plugin architecture (and the
objects persist their own state) it is hard to determine where the
delta data size is coming from.

The best 'documentation' I've found is located
http://primates.ximian.com/~lluis/di...ion_format.htm
. It appears however that the sscli20 has the implementation code for
the formatters so I could probably work it out from there - but that
is not something on my fun to do list!

The format is 'formatted', but just not in a human readable manner.
The deserialization knows how to read it, and reconstitute the
encapsulated objects. I'm only looking for the size of the objects :-)

So unless someone has written a 'summarization' reader of
binaryformatted to determine sizes and graphs of the data, and there
isnt a API to get the size of the individual data elements within the
stream I'll have to either write one - or poke around with notepad to
see what is being persisted and shouldn't be!!

On May 1, 9:09 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>Gareth,

I doubt there is, as the document isn't formatted.

Because it isn't formatted, I have to wonder how you are formulating
the
idea that the serialized instance is larger than you expect. There is
nothing to base that idea on.

How big are the files, and what is the size that you are expecting
them
to be? Also, is the file size really causing that much of a problem?

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

May 1 '07 #4
Thanks,

I'll have a look at the object tree just prior to serialization. For
now we are in control of the objects (just not me personally), and
I'll have a look at the in memory tree to see if it yields any
pointers (thanks for that suggestion).

I'm still a little surprised that there isnt a way to 'dump' the
serialized file into an object tree showing sizes as that seems the
most expeditious route if the tool existed. But oh well! Perhaps when
I get time I'll write one (assuming no one subsequently points me to a
pre-existing tool)

Thanks,

On May 1, 10:50 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Well, if you are not in control of the plug ins, then there is little
you can do. If the plug ins are under your control, then the same
techniques you apply to the main object being serialized can be applied to
the objects attached to the graph by the plug ins.

The very first thing I would look at is to make sure you are not
serializing any delegate chains to the graph. Delegates will end up
serializing every object that they hold a reference to (assuming that you
are holding a delegate to an instance method), and that could easily add the
overhead you are seeing if you have objects subscribing to events that the
serialized object is exposing.

The easy way to get around this is to mark the events with NonSerialized
attribute, using the field indicator, like so:

[field:NonSerialized]
public event EventHandler MyEvent;

That should keep your events from not being serialized (assuming this is
the case in the first place).

If it is not, to be honest, I would just look at the object tree in the
debugger at the point before you serialize. You should be able to easily
determine (with enough digging) which objects are necessary and which are
not.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
May 1 '07 #5

Temporarily switch to use the SoapFormatter instead of
BinaryFormatter. Then the serialized form will be easily readable.
Once you know where the rogue objects are you can switch back to
binary formatting.

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 30 Apr 2007 20:11:28 -0700, go**************@theisaacfamily.co.uk
wrote:
>
I have a custom set of objects that is correctly serializing &
deserializing the object tree. However in some cases the size of the
resultant serialization is larger than I would expect. Is there any
documented way to pull apart the stream to determine the sizes of the
objects embedded within the file? For example if I open the file up in
a Hex editor the 'containing' format looks reasonably simple to
decode, but I would rather be coding business logic rather than
figuring out a custom file format! Is the format documented (or
accessible via API)?

What I am looking for is a way to see all the of the named of the
serialized object within a stream with a count of the instances and
number of bytes taken up by the serialization.

Is there a mechanism or tool to do this?

Many thanks,

Gareth
May 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: aladdinm1 | last post by:
Hi All, I have an annoying trouble with binary serialization. I have a windows forms application which works like a server and keeps sending data to its clients. The data is serialized before...
4
by: Jeff T. | last post by:
Hello, I have an existing set of C# classes that encapsulate our application data. They are in a heirachy with each subclass defining more specific types of data. I would like to serialize these...
3
by: Joshua Moore | last post by:
I have a webservice that serializes a ton of variables and other good stuff to a txt file using SoapFormatter (IFormatter), and when I try to deserialize it using the binary formatter, i get the...
11
by: Igor | last post by:
Hi. While executing BinaryFormatter.Deserialize() I get: System.InvalidCastException: Specified cast is not valid. I implemented ISerializable interface. What may be a problem? Thanks.
0
by: Fruber Malcome | last post by:
I'm getting a very weird exception and hoping someone may be able to help. I have an Office Add-In that lives in a .dll (for email reference ai.dll) ai.dll makes calls into the core part of the...
19
by: Sharon | last post by:
Hi, When I'm doing BinaryFormatter.Deserialize() over a TCP socket. When I'm closing the TcpListener by invoking the TcpListener.Stop(); I get: System.IO.IOException with message "Unable to...
2
by: Doug Lind | last post by:
Hi all, I have seen a number of posts re: the BinaryFormatter version incompatibility but nothing on how to recover from it. In my case, I want the exception to trigger an alternate behaviour...
2
by: Lambuz | last post by:
Hi all, I'm triying to create a prototype of a smart client that using .NET Remoting. I've got an assembly loaded into an HTML page by a tag object <OBJECT id="myID" height="150" width="300"...
1
by: Tarscher | last post by:
Hi all, i want to save my application to a file with a BinaryFormatter . I have some questions how the BinaryFormatter will work when the I update my application. How can I make sure that I can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.