title: JSON deserialize List<SomeObject> is not working
body: <p>We are deserializing the JSON using C# System.Runtime.Serialization.Json.DataContractJsonSerializer. It is working for normal objects but not for List.</p>
  
  <p>For example if the json string is below then it works fine:</p>
  
  <pre><code>{"CacheInsertDateTime":"\/Date(1360761324878)\/","Data":{"__type":"SomeObject:#ConsoleApplication1","Symbol":"some string"}}
  </code></pre>
  
  <p>But if the josn is below:</p>
  
  <pre><code>{"CacheInsertDateTime":"\/Date(1360761324878)\/","Data":[{"__type":"SomeObject:#ConsoleApplication1","Symbol":"some string"},{"__type":"SomeObject:#ConsoleApplication1","Symbol":"some other string"}]}
  </code></pre>
  
  <p>The data comes as <code>List&lt;Object&gt;</code> not <code>List&lt;SomeObject&gt;</code>. I attached the sample solution also, showing the same problem. Any help or direction is appreciated.</p>
  
  <p>EDIT: added the code</p>
  
  <p>{</p>
  
  <p>namespace ConsoleApplication1
            {
      class Program
      {
          /* Someobject class*/
          [DataContract]
          public class SomeObject
          {
              public SomeObject(string sym)
              {
                  this.Symbol = sym;
              }
              [DataMember]
              public string Symbol { get; set; }</p>
  
  <pre><code>    }
      /* Cahe Data */
      [DataContract()]
      [KnownType("GetKnownTypes")]
      class CacheData
      {
          [DataMember()]
          public object Data { get; set; }
  
          [DataMember()]
          public DateTime CacheInsertDateTime { get; set; }
  
          public static IEnumerable&lt;Type&gt; GetKnownTypes(ICustomAttributeProvider provider)
          {
              return GetKnownTypes();
          }
          public static IEnumerable&lt;Type&gt; GetKnownTypes()
          {
              if (knownTypes == null)
              {
                  // Since reflection is costly, we will do the lookup once for the known types and persist the data in knownTypes variable
                  knownTypes = new List&lt;Type&gt;();
  
                  // first add types from DataModel assembly get types which are marked with DataContract attribute
                  var typesInCurrentAssembly = Assembly.GetExecutingAssembly().GetTypes().Where
                      (t =&gt; t.GetCustomAttributes(false).Any(attrib =&gt; attrib is DataContractAttribute));
                  foreach (var type in typesInCurrentAssembly)
                  {
                      // add type and list&lt;type&gt; also to the known types list
                      knownTypes.Add(type);
                      knownTypes.Add(typeof(List&lt;&gt;).MakeGenericType(type));
                  }
  
                  knownTypes.Add(typeof(DataTable));
              }
              return knownTypes;
          }
          private static List&lt;Type&gt; knownTypes = null;
      }
  
      /*Cache Response Class*/
      class CacheResponse&lt;T&gt; where T : class
      {
          public CacheData CacheData { get; set; }
          public T Data
          {
              get{return (CacheData != null &amp;&amp; CacheData.Data.GetType() == typeof(T)) ? CacheData.Data as T: null;}
          }
      }
      /* Main class */
      static void Main(string[] args)
      {   
          //1. first with someobject, it works same as above
          string jsonString = "{\"CacheInsertDateTime\":\"\\/Date(1360761324878)\\/\",\"Data\":{\"__type\":\"SomeObject:#ConsoleApplication1\",\"Symbol\":\"some object 1\"}}";
          CacheData obj = null;
          byte[] byteData = Encoding.UTF8.GetBytes(jsonString);
          using (MemoryStream stream = new MemoryStream(byteData))
          {
              var serializer = new DataContractJsonSerializer(typeof(CacheData));
              obj = serializer.ReadObject(stream) as CacheData;
          }
          CacheResponse&lt;SomeObject&gt; response1 = new CacheResponse&lt;SomeObject&gt;();
          response1.CacheData = obj;
          SomeObject responseObj = response1.Data; //this response object is fine            
  
          //2. with list&lt;someobject&gt;, it does not work
          jsonString = "{\"CacheInsertDateTime\":\"\\/Date(1360761324878)\\/\",\"Data\":[{\"__type\":\"SomeObject:#ConsoleApplication1\",\"Symbol\":\"some object 1\"},{\"__type\":\"SomeObject:#ConsoleApplication1\",\"Symbol\":\"some object 2\"}]}";
          byteData = Encoding.UTF8.GetBytes(jsonString);
          using (MemoryStream stream = new MemoryStream(byteData))
          {
              var serializer = new DataContractJsonSerializer(typeof(CacheData));
              obj = serializer.ReadObject(stream) as CacheData;
          }
          CacheResponse&lt;List&lt;SomeObject&gt;&gt; response2 = new CacheResponse&lt;List&lt;SomeObject&gt;&gt;();
          response2.CacheData = obj;
          List&lt;SomeObject&gt; responseList = response2.Data;//this is null            
      }
  }
  </code></pre>
  
  <p>}</p>