title: Json.net serialization of custom collection implementing IEnumerable<T>
body: <p>I have a collection class that implements IEnumerable and I am having trouble deserializing a serialized version of the same. I am using Json.net v 4.0.2.13623</p>
  
  <p>Here is a simplier version of my collection class that illustrates my issue</p>
  
  <pre><code>public class MyType
  {
    public int Number { get; private set; }
    public MyType(int number)
    {
      this.Number = number;
    }
  }
  
  public class MyTypes : IEnumerable&lt;MyType&gt;
  {
    private readonly Dictionary&lt;int, MyType&gt; c_index;
    public MyTypes(IEnumerable&lt;MyType&gt; seed)
    {
      this.c_index = seed.ToDictionary(item =&gt; item.Number);
    }
    public IEnumerator&lt;MyType&gt; GetEnumerator()
    {
      return this.c_index.Values.GetEnumerator();
    }
    IEnumerator IEnumerable.GetEnumerator()
    {
      return this.GetEnumerator();
    }
    public int CustomMethod()
    {
      return 1;  // Just for illustration
    }
  }
  </code></pre>
  
  <p>When I serialize it i get the following json</p>
  
  <pre><code>[
    {
      "Number": 1
    },
    {
      "Number": 2
    }
  ]
  </code></pre>
  
  <p>But then when i try to deserialize i get the following exception
  System.Exception: Cannot create and populate list type MyTypes</p>
  
  <p>Have also tried using serialization hints but have had no success</p>
  
  <p>These are the test function i have used</p>
  
  <pre><code>public void RoundTrip()
  {
    var _myTypes1 = new MyTypes(new[] { new MyType(1), new MyType(2) });
    var _jsonContent = JsonConvert.SerializeObject(_myTypes1, Formatting.Indented);
    var _myTypes2 = JsonConvert.DeserializeObject&lt;MyTypes&gt;(_jsonContent);
  }
  public void RoundTripWithSettings()
  {
    var _myTypes1 = new MyTypes(new[] { new MyType(1), new MyType(2) });
  
    var _serializationSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Arrays };
    var _jsonContent = JsonConvert.SerializeObject(_myTypes1, Formatting.Indented, _serializationSettings);
    var _myTypes2 = JsonConvert.DeserializeObject&lt;MyTypes&gt;(_jsonContent, _serializationSettings);
  }
  </code></pre>
  
  <p>Has anybody managed to serialize their own collection objects ?</p>
  
  <p>Thanks in advance</p>
  
  <p>Pat</p>