I don't believe you can use the XmlSerializer on an array of objects in the 2008 version of .Net. I tried your code in Visual Studio 2012 and it works fine.
As a work-a-round, you could create a containing class with a property that is an array. Then you serialize this class.
For example (C# notation)
Code:
[Serializable]
public class TridaDats
{
[XmlElement]
public TridaDat[] Entries { get; set; }
}
var xmlSerializer = new XmlSerializer(typeof(TridaDats));
...
XML-serializing an array shouldn't be a problem. In fact I do that myself all the time. However, most of the more advanced collections can't be XML-serialized that easily. If I need to serialize one of those, I've made the habit to first convert them to an array and then serialize that. Advanced features like implicit sorting or keyed access don't really need to be serialized anyway in most cases and can be reconstructed upon deserialization. And even though it's a rather plain kind of a collection, AFAIR an ArrayList is one of those that can't be XML-serialized, and I think that's what the error message is trying to tell the OP. Unlike the error message, the original code snippet doesn't mention that collection type, but I suspect the array item type TridaDat contains a field of that type.
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.
Bookmarks