Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Derive from TreeNode class and serialization

Wonder if anyone knows the solution:
I'm building a treeview with MyTreeNode objects that inherit from TreeNode class.
Serialization with ordinary TreeNode objects works fine, but when I use MyTreeNode it fails!
MSDN tells me that TreeNode implements ISerializable, but it doesn't(!?) At least not in a way MyTreeNode can override the ISerializable::GetObjectData method... .

Does anyone have an idea, assuming I did try to use ISerializable, made sure that the constructor of MyTreeNode calls base() and taking for granted I'm a little bit stupid?

Monday, November 8, 2004

Check the exception that you get when trying to serialize, and drill down into the InternalException, that should give you more details.

GD (
Monday, November 8, 2004

Thank you, but that is what I did actually.
It just seems that since TreeNode does not implement ISerializable it just won't work.... ??

Wednesday, November 10, 2004

Why not implement it yourself then ?

As with all these cases, if the framework doesn't do what you want, extend it, or re-write it, so that it does.

Obviously, I mean just extend/re-write the bit you need to be different ;-)

Nemesis [µISV]
Wednesday, November 10, 2004

You mean, implement ISerializable so, that the base() TreeNode get's serialized correctly?
No, thank you, since TreeNode IS serializable as is, if not used as a base class....
Or, am I missing something?

Btw. I did find that putting some custom class-object in the Tag property of a TreeNode, in order to control the TreeNode, does the trick... but that solution makes the nodes a little less flexible for future changes... 

Wednesday, November 10, 2004

*  Recent Topics

*  Fog Creek Home