title: Object serializing/deserializing doesn't work
body: <p>I have an extension method for <code>System.Object</code> to serialize and deserialize objects using <code>Json.Net</code>. this is my Extension methods:</p>
  
  <pre><code>public static void SaveToFile(this object data, string FileName)
  {
      using (StreamWriter writer = new StreamWriter(FileName))
      {
          string encode = WpfApplication.Helper.Encrypt(JsonConvert.SerializeObject(data));
          writer.Write(encode);
          writer.Close();
      }
  }
  
  public static void LoadFromFile&lt;t&gt;(this object data, string FileName)
  {
      using (StreamReader reader = new StreamReader(FileName))
      {
  
          data = JsonConvert.DeserializeObject&lt;t&gt;(WpfApplication.Helper.Decrypt(reader.ReadToEnd()));
          reader.Close();
      }
  }
  </code></pre>
  
  <p>and It's the class that I want to deserialize:</p>
  
  <pre><code>public class CardPack
  {
      #region Properties
      private string name;
  
      public string Name
      {
          get { return name; }
          set { name = value; }
      }
  
      private List&lt;FlashCard&gt; cards;
  
      public List&lt;FlashCard&gt; Cards
      {
          get { return cards; }
          set { cards = value; }
      }
  
      private bool registered;
      public bool Registered
      {
          get { return registered; }
          set { registered = value; }
      }
  
      private int currentCardIndex;
  
      public int CurrentCardIndex
      {
          get { return currentCardIndex; }
          set { currentCardIndex = value; }
      }
  
      public string RegisterKey { get; set; }
  
      public string ViewName { get; set; }
  
      public List&lt;FlashCard&gt; TodayCards { get; set; }
      #endregion
      ~CardPack()
      {
          foreach (FlashCard card in cards)
          {
              card.Check();
          }
          currentCardIndex = 0;
          TodayCards = null;
          this.SaveToFile(string.Format(System.IO.Path.GetDirectoryName(
    System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Split(@"file:\\")[1] + @"\Packs\{0}.json", name));
      }
  </code></pre>
  
  <p>but whenever I deserialize the class <code>cards</code> is empty and I don't know how to resolve the problem. Can anybody help me?</p>
  
  <p><strong>Update</strong>
  I find the error when I had this code:</p>
  
  <pre><code>public CardPack(string Name)
      {
          this.name = Name;
          this.LoadFromFile&lt;CardPack&gt;(string.Format(System.IO.Path.GetDirectoryName(
    System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Split(@"file:\\")[1] + @"\Packs\{0}.json", name));
          foreach (var item in cards)
          {
              if (item.NextTime == null)
              {
                  int a = 0;
              }
          }
          TodayCards = cards.Where(c =&gt; c.NextTime.Date == DateTime.Today).ToList();
      }
  </code></pre>
  
  <p>because the application closed when it tries to run <code>foreach (var item in cards)</code>!
  I asked <a href="https://stackoverflow.com/questions/12509607/linq-query-close-my-wpf-application">here</a> and found out that <code>cards</code> is empty!</p>
  
  <p><strong>update2</strong> I serialized the <code>CardPack</code> object with a little different structure. in previous structure <code>Cards</code> property was read-only.</p>