Problem w/ Simple Serialization

  • Thread starter Thread starter Ron M. Newman
  • Start date Start date
R

Ron M. Newman

Hi,

I have a simple class that has a Hashtable. the hashtable has a couple of
key/value pairs where the key is a string and the value is also a strong.

I have [Serializable] at the top of that class.

when I try to serialize it with XmlSerializer, I get only the "class
boundary" but my hashtable member doesn't get serialized. Hashtable is
Serializable, at least that's what the documentation says.

Am I missing something?

Thanks,
Ron
 
There are 2 kinds of Serialization: "Binary" and XML. The [Serializable]
attribute relates to binary serialization, and HashTable cannot be
serialized as XML.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
 
Ron M. Newman said:
I have a simple class that has a Hashtable. the hashtable has a couple of
key/value pairs where the key is a string and the value is also a strong.

I have [Serializable] at the top of that class.

when I try to serialize it with XmlSerializer, I get only the "class
boundary" but my hashtable member doesn't get serialized. Hashtable is
Serializable, at least that's what the documentation says.

Am I missing something?

Yup. Hashtable isn't serializable with XmlSerializer, and XmlSerializer
is a different thing than the [Serializable] attribute.

XmlSerializer deals with hierarchical object trees - it can't handle
cycles etc. It also only works with public read/write properties. It
works with the Xml* attributes in System.Xml.Serialization. You can
implement an interface to create custom serialization of your hashtable
data: IXmlSerializable.

[Serializable] is for use with the types in
System.Runtime.Serialization, and serialization formatters such as
BinaryFormatter and SoapFormatter. It works with private members, and
can handle arbitrary object graphs, so long as all the objects are
serializable.

-- Barry
 
Back
Top