.NET Serialization Exception: System.InvalidOperationException: You must implement the default accessor in System.Collections.Generic.Stack`1

All I try to do is

XmlSerializer serializer = new XmlSerializer(typeof(Stack<int>));

      

and at runtime I get this:

System.InvalidOperationException

: you must implement the default accessor to System.Collections.Generic.Stack

`1 [[System.Int32, mscorlib, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089]] because it inherits from ICollection.

Shouldn't I serialize Stack<int>

?

+1


source to share


1 answer


Since the Stack class does not have a default accessory (for example, by index), you cannot serialize it using this method.

I would suggest copying your stack to a list and then serializing the list.



List<int> serializableLIst = new List<int>( myStack );
XmlSerializer serializer = new XmlSeralizer(typeof(List<int>));

      

See if it works better.

+8


source







All Articles