title: List<T> inside serializable object not deserializing correctly in C#
body: <p>I have this object called MyObject in C# and I've been trying to make it so that we can take this object, serialize it to JSON, use that JSON to populate other lists in JavaScript, etc, and then use the resulting changed JSON string to be fed back into the MyObject object and change its values. However, whenever I call Json() on this object, it gives me correctly serialized JSON, but when I feed that exact JSON back into the UpdateFromJson(string json) method, it claims that the List is of count=0 and I get none of my List objects in the new object. The other properties populate just fine; the only problem is with the List.</p>
  
  <p>Here is the (dumbed down) class without the properties but with the relevant methods and List of objects. It should be noted that the List contains objects that I defined elsewhere in the namespace, i.e. they're not in the C# framework anywhere, they're custom.</p>
  
  <pre><code>[Serializable]
  public class MyObject
  {
    public MyObject()
    {
      this.Elements = new List&lt;MyObjectElement&gt;();
    }
  
    public List&lt;MyObjectElement&gt; Elements { get; private set; }
  
    public string Json()
    {
      JavaScriptSerializer serializer = new JavaScriptSerializer();
      return serializer.Serialize(this);
    }
  
    public void UpdateFromJson(string json)
    {
      System.Web.Script.Serialization.JavaScriptSerializer serializer = new JavaScriptSerializer();
      MyObject temp = serializer.Deserialize&lt;MyObject&gt;(json);
  
      foreach (PropertyInfo property in temp.GetType().GetProperties())
      {
        object value = property.GetValue(temp, null);
        if (value != null)
        {
          if (value.GetType() == typeof (List&lt;MyObjectElement&gt;))
          {
            foreach(MyObjectElement le in (List&lt;MyObjectElement&gt;)value)
            {
              this.Elements.Add(le);
            }
          }
        }
        property.SetValue(this, value, null);
      }
    }
  }
  </code></pre>
  
  <p>Like I said, the only issue I'm having is, for example when <code>serializer.Deserialize&lt;MyObject&gt;(json)</code> happens, the List has nothing in it when, in fact, the actual JSON string (I've had it printed to a browser and have tested it in JSONLint) contains data for Elements. It just seems that <code>Deserialize(json)</code> is not able to retrieve the List in a format it can parse, or something, I'm not sure.</p>