This project has moved and is read-only. For the latest updates, please go here.

Cannot deserialize XNA Rectangle. Why?

Jul 28, 2011 at 6:18 AM

First look at this:



using System.Drawing;
string json = JsonConvert.SerializeObject(new Rectangle(-3,6,32,32), Formatting.Indented);
Rectangle deserializedRectangle = JsonConvert.DeserializeObject<Rectangle>(json);



Everything works as expected.

The console output is this:

"-3, 6, 32, 32"


But when I want to do the same thing with the XNA Rectangle, I get an error. (replaced the old using with this "using Microsoft.Xna.Framework;")

So the new Rectangle is this:


The console output is this:

"{X:-3 Y:6 Width:32 Height:32}"

and the error it throws is: "Error converting value "{X:-3 Y:6 Width:32 Height:32}" to type 'Microsoft.Xna.Framework.Rectangle'."


1. )Why is this happening?

2.) Whats going wrong, and how do I fix this??