views:

27

answers:

1

I'm serializing the data in my app using custom serialization i.e. each of the classes I'm storing has the [Serializable] attribute and implements ISerializable. The object graph being serialized is reasonably complex with lots of cross-references between the objects/classes. The serialization works, but it's pretty slow. :(

By putting a breakpoint in each relevant class's GetObjectData method, I've found that I'm getting many, many more hits than I've got objects.

I'm confused - my understanding of the serialization framework was that it would store each object only once, even if the object graph contained multiple references to it. I assumed that this meant each object's GetObjectData method would need to be called only once during saving. Am I wrong?

And if so, is there anything I can do in this approach to reduce the number of calls to my classes' GetObjectData methods?

Thanks.

+2  A: 

The MSDN docs do not guarantee just 1 call per object instance.

Have you tried this with different formatters? There are comments here to the effect that selected work was being done to improve this. specifically for Indigo (aka WCF).

It is not guaranteed that this method will be called only once per object instance during serialization. Therefore, the method should be implemented in such a way that its behavior will be the same regardless of the number of times it is called.

Steve Townsend
Thanks - hadn't spotted that.
Mal Ross
Turns out, in the end, that I hadn't spotted something pretty fundamental in my object graph. One of the properties I was serializing returned a collection of objects created anew, on-the-fly every time the property was accessed. Not only that, but each object held references to other parts of the graph. Frankly, it's a miracle the serialization ever finished. Ooops.
Mal Ross
@Mal - glad you got this sorted out
Steve Townsend