Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Inheriting ListViewItem Serialize/Deserialize Problem

I'm trying to derive a class from System.Windows.Forms.ListViewItem rather than use the Tag property. It has to be able to serialize and deserialize. It compiles OK and appears to serialize OK (using BinaryFormatter), but I get a SerializationException when deserializing, with the message that I don't have an appropriate constructor for my class. From perusing the docs on custom serialization (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconCustomSerialization.asp) it appears my class needs to have the signature MyObject(SerializationInfo info, StreamingContext context). And I can't implement that because ListViewItem's constructor of that signature is private.

So is it possible to derive from ListViewItem and do serialization? MSDN implies it is. For example, there are protected Serialize/Deserialize methods that have a note to inheritors (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewitemclassdeserializetopic.asp). But I don't understand how to use them. They are not part of the ISerializable interface, and ListViewItem doesn't even implement the GetObjectData that ISerializable calls for.

I have tried implementing an empty MyObject() constructor and also just implement the Serialize and Deserialize methods (calling the base ListViewItem ones), but I keep getting the same exception from the Deserialize.

Any ideas or should I just use Tag?

Raj
[1529 byte] By [rajm] at [2007-11-11 6:54:13]