Deserialize Generic Stack Class

Oct 18, 2010 at 8:03 AM

I want to serialize / deserialize a Generic Stack object.

Serializing is no problem but when deserializing I get the following error ...

Cannot create and populate list type System.Collections.Generic.Stack`1[System.String].

Stack<string> stringStack = new Stack<string>();

stringStack.Push("abc");

stringStack.Push("def");

string serializedStack = JsonConvert.SerializeObject(stringStack);

// this line errors

Stack<string> newStack = JsonConvert.DeserializeObject<Stack<string>>(serializedStack);

Am I doing something wrong?