title: json.net Unable to Deserialize to Object List
body: <p>I am trying to create a JSON file that contains a list of parts for computers.</p>
  
  <p>My Parts Class</p>
  
  <pre><code>namespace Part_Class
  {
      public class Part_DB : IEnumerable&lt;Part&gt;
      {
          public List&lt;Part&gt; Parts = new List&lt;Part&gt;();
  
          public IEnumerator&lt;Part&gt; GetEnumerator()
          {
              return this.Parts.GetEnumerator();
          }
  
          IEnumerator IEnumerable.GetEnumerator()
          {
              return GetEnumerator();
          }
      }
  
      public class Model
      {
          public String Name { get; set; } // E6430, M4600, T4220
  
          public Model(string Name)
          {
              this.Name = Name;
          }
      }
  
      public class Category
      {
          public String Name { get; set; } // E6430, M4600, T4220
  
          public Category(string Name)
          {
              this.Name = Name;
          }
      }
  
      public class Part
      {
          public List&lt;Model&gt; Models = new List&lt;Model&gt;(); //E6420
          public string PartNumber { get; set; } //PPHPX, UK717
          public string Description { get; set; } // "320GB Hard Drive", "E6410 keyboard"
          public List&lt;Category&gt; Categories = new List&lt;Category&gt;(); //Hard Drive, Keyboard 
          public bool HeroKit { get; set; } //Y or N
      }
  }
  </code></pre>
  
  <p>First I create a handful of Model, Categories, and Parts.</p>
  
  <pre><code>....
  Model E6410 = new Model("E6410");
  Model M4600 = new Model("M4600");
  Model M4700 = new Model("M4700");
  
  Category Keyboard = new Category("Keyboard");
  Category Hard_Drive = new Category("Hard Drive");
  
  Part PPHPX = new Part();
  PPHPX.PartNumber = "PPHPX";
  PPHPX.Models.Add(M4600);
  PPHPX.Models.Add(M4700);
  PPHPX.Description = "320GB Spindle Hard Drive";
  PPHPX.Categories.Add(Hard_Drive);
  PPHPX.HeroKit = true;
  
  Part UK717 = new Part();
  UK717.PartNumber = "UK717";
  UK717.Models.Add(E6410);
  UK717.Description = "102 Key Non Backlit";
  UK717.Categories.Add(Keyboard);
  UK717.HeroKit = true;
  
  //I store those parts into a Part_DB Object
  Part_DB Stored = new Part_DB();
  Stored.Parts.Add(PPHPX);
  Stored.Parts.Add(UK717);
  
  //Then take that object and serialize it into a string
  string jsonStr = JsonConvert.SerializeObject(Stored, Formatting.Indented);  
  
  //Then save it to a file
  System.IO.File.WriteAllText(@"C:\****\Parts.json", jsonStr);
  ....
  </code></pre>
  
  <p>This outputs the following json file.</p>
  
  <pre><code>[
    {
      "Models": [
        {
          "Name": "M4600"
        },
        {
          "Name": "M4700"
        }
      ],
      "Categories": [
        {
          "Name": "Hard Drive"
        }
      ],
      "PartNumber": "PPHPX",
      "Description": "320GB Spindle Hard Drive",
      "HeroKit": true
    },
    {
      "Models": [
        {
          "Name": "E6410"
        }
      ],
      "Categories": [
        {
          "Name": "Keyboard"
        }
      ],
      "PartNumber": "UK717",
      "Description": "102 Key Non Backlit",
      "HeroKit": true
    }
  ]
  </code></pre>
  
  <p>I am having trouble doing the reverse. Deserialize the JSON file back into a Part_DB Object. Here is my attempt</p>
  
  <pre><code>List&lt;string&gt; errors = new List&lt;string&gt;();
  
  try
  {
      //Create a string of the JSON File
      string jsonStr;
      using (StreamReader file = File.OpenText(@"C:\****\Parts.json"))
      {
          jsonStr = file.ReadToEnd();
      }
  
      // Deserilize object into the Part_DB
      Part_DB Stored = JsonConvert.DeserializeObject&lt;Part_DB&gt;(jsonStr,
          new JsonSerializerSettings
          {
              Error = delegate(object senders, Newtonsoft.Json.Serialization.ErrorEventArgs args)
              {
                  errors.Add(args.ErrorContext.Error.Message);
                  //Debug.WriteLine(args.ErrorContext.Error.Message);
                  args.ErrorContext.Handled = true;
              },
          });
  }
  catch (Exception ex) {
      Console.WriteLine(ex);
  }
  </code></pre>