title: Serialization of properties in JSON.NET throws Exception
body: <p>Here is a sample application that shows custom serialization using a JsonConverter for a List.  I register a custom JsonSerializerSettings with JsonConvert.  These settings have my ListOfGuidConverter installed.</p>
  
  <p>This works beautifully when you are serializing and deserializing a List as the root object of serialization.  As soon as you have a different root object and the List is a property, JSON.Net throws exceptions saying unexpected end.</p>
  
  <p>What can I do to fix this?</p>
  
  <p>Thanks Rich</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Newtonsoft.Json;
  using PB8.Peep;
  
  namespace JsonTest
  {
      class Program
      {
          static void Main(string[] args)
          {
              try
              {
                  var ListOfGuidsConverter = new ListJsonConverter&lt;Guid&gt;();
                  var jss = new JsonSerializerSettings();
                  jss.Converters.Add(new ListofGuidJsonConverter());
  
                  string value1 = JsonConvert.SerializeObject(GetSampleList());
                  Console.WriteLine(value1);
  
                  JsonConvert.DefaultSettings = () =&gt; jss;
  
                  string value2 = JsonConvert.SerializeObject(GetSampleList());
                  Console.WriteLine();
                  Console.WriteLine(value2);
  
                  var value3 = JsonConvert.DeserializeObject&lt;List&lt;Guid&gt;&gt;(value2);
  
                  string value4 = JsonConvert.SerializeObject(value3);
  
                  Console.WriteLine();
                  Console.WriteLine(value4);
  
                  var value5 = JsonConvert.SerializeObject(GetSample());
                  Console.WriteLine();
                  Console.WriteLine(value5);
  
                  var value6 = JsonConvert.DeserializeObject&lt;Sample&gt;(value5);
  
                  var value7 = JsonConvert.SerializeObject(value6);
  
                  Console.WriteLine();
                  Console.WriteLine(value7);
  
              }
              catch (Exception ex)
              {
                  Console.WriteLine(ex);
              }
              finally
              {
                  Console.ReadLine();
              }
          }
  
          public static List&lt;Guid&gt; GetSampleList()
          {
              return new List&lt;Guid&gt;
              {
                  Guid.NewGuid(),
                  Guid.NewGuid(),
                  Guid.NewGuid()
              };
          }
  
          public static Sample GetSample()
          {
              Sample s = new Sample();
              s.List1.Add(Guid.NewGuid());
              s.List1.Add(Guid.NewGuid());
              s.List1.Add(Guid.NewGuid());
              s.List1.Add(Guid.NewGuid());
              s.List1.Add(Guid.NewGuid());
  
              return s;
          }
  
          public class Sample
          {
              public Sample()
              {
                  List1 = GetSampleList();
              }
  
              public List&lt;Guid&gt; List1 { get; set; }
          }
      }
  
  
  
  
      public class ListofGuidJsonConverter : JsonConverter
      {
          private const string CapacityPropertyName = "c";
          private const string ListPropertyName = "l";
          private static readonly Type _type = typeof(List&lt;Guid&gt;);
  
          public override bool CanConvert(Type objectType)
          {
              bool canConvert = objectType == _type;
              return canConvert;
          }
  
          public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
          {
              const int DefaultCapacity = 4;
  
              if (reader.TokenType == JsonToken.StartObject)
                  reader.Read();
  
              if (reader.TokenType == JsonToken.PropertyName)
                  reader.Read();
  
              int capacity = DefaultCapacity;
              if (reader.TokenType == JsonToken.Integer)
              {
                  capacity = Convert.ToInt32(reader.Value);
                  reader.Read();
              }
  
              var listOfT = new List&lt;Guid&gt;(capacity);
  
              if (reader.TokenType == JsonToken.PropertyName)
                  reader.Read();
  
              if (reader.TokenType == JsonToken.StartArray)
                  reader.Read();
  
              for (int i = 0; i &lt; capacity; i++)
              {
                  var item = new Guid(Convert.ToString(reader.Value));
                  listOfT.Add(item);
                  reader.Read();
              }
  
              if (reader.TokenType == JsonToken.EndArray)
                  reader.Read();
  
              if (reader.TokenType == JsonToken.EndObject)
                  reader.Read();
  
              return listOfT;
          }
  
          public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
          {
              var listOfT = (List&lt;Guid&gt;)value;
  
              writer.WriteStartObject();
  
              writer.WritePropertyName(CapacityPropertyName);
              writer.WriteValue(listOfT.Count);
  
              writer.WritePropertyName(ListPropertyName);
              writer.WriteStartArray();
  
              foreach (var item in listOfT)
                  writer.WriteValue(item);
  
              writer.WriteEndArray();
  
              writer.WriteEndObject();
          }
      }
  }
  </code></pre>