At the XmlSerializer constructor line the below causes an InvalidOperationException which also complains about not having a default accesor implemented for the generic type.
Queue<MyData> myDataQueue = new Queue<MyData>();
// Populate the queue here
XmlSerializer mySerializer =
new XmlSerializer(myDataQueue.GetType());
StreamWriter myWriter = new StreamWriter("myData.xml");
mySerializer.Serialize(myWriter, myDataQueue);
myWriter.Close();
It would be easier (and more appropriate IMO) to serialize the data from the queue - perhaps in a flat array or List<T>
. Since Queue<T>
implements IEnumerable<T>
, you should be able to use:
List<T> list = new List<T>(queue);