By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,080 Members | 1,748 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,080 IT Pros & Developers. It's quick & easy.

Problem w/ Simple Serialization

P: n/a
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
Aug 11 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <co**********@confideltial.comwrote in message
news:eF**************@TK2MSFTNGP02.phx.gbl...
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

Aug 11 '06 #2

P: n/a
"Ron M. Newman" <co**********@confideltial.comwrote:
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

--
http://barrkel.blogspot.com/
Aug 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.