Skip to content

Instantly share code, notes, and snippets.

@haacked
Created June 8, 2020 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haacked/fe3624b3231e08d135073d8ce68c1e20 to your computer and use it in GitHub Desktop.
Save haacked/fe3624b3231e08d135073d8ce68c1e20 to your computer and use it in GitHub Desktop.
JsonConvert Bug?
[Fact]
public void StackTest()
{
var stack = new Stack<string>();
stack.Push("one");
stack.Push("two");
stack.Push("three");
var serialized = JsonConvert.SerializeObject(stack, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All
});
var deserialized = JsonConvert.DeserializeObject<Stack<string>>(serialized);
Assert.Equal("three", deserialized.Pop()); // This fails because `Pop()` returns "one" here.
}
@haacked
Copy link
Author

haacked commented Jun 8, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment