November 25th, 2010, 08:24 PM
XML serialization woes regarding collections
This is a spin-off of http://www.codeguru.com/forum/showthread.php?t=504635, in particular posts #10 and #12. Those who might be interested in the history of why I posted this might have a look over there. I have detached it from there as it could be of interest by itself.
In order to produce the XML Arjay has asked for, I did some experiments on XML serialization, and it appears to summon a host of new problems.
It turned out to be really tricky to serialize collections. According to MSDN, a collection can't be serialized if it's either an ArrayList or a List<T>. As I found out during my experiments by examining the exceptions I got, for some obscure (at leat to me) reasons it also can't be serialized if it implements IDictionary, what I didn't find mentioned in the docs. But for what purpose the heck then does Dictionary<TKey, TValue> implement ISeializable as well? These conditions together rule out a whole lot of the available collections when it comes to serialization.
During my desperate search for a candidate I came across SortedSet<T>, which doesn't really fit the concept of the collection I was looking for, though could be twisted to fit in a pinch. But it gets ruled out by another condition mentioned on the MSDN page I linked to above: If it does implement ICollection (which it does) it needs to have a public indexer that takes an int (which it does not).
And, BTW, the ConfigurationProperty class isn't serializable either, as it doesn't have a default constructor. (The configuration infrastructure somehow manages to store it to the config files, but it is not accepted by XmlSerializer.)
I feel that serialization really isn't that much fun if it is that hard to use it for collections. Or did I fall to some fundamental misunderstanding here?
These exceptions that get thrown by the CLR types involvd here can be really informative if examined carefully. That's nice, but it doesn't really help me out either...
Yes, I know this is a post with maybe too many s. But maybe someone can help me to get out of this calamity.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Tags for this Thread
Click Here to Expand Forum to Full Width