title: How to debug XML deserialization?
body: <p>I was wondering if you had any tips on how I can debug the below XML deserialization? I cannot get it to work. The deserializer basically creates the summon and slash instances, but all their properties are empty. The relevant classes to are shown below.</p>
  
  <hr>
  
  <p><strong>SkillCollection class with Deserializer:</strong></p>
  
  <pre><code>[DataContract(Name = "Skills", Namespace = "")]
  public class SkillCollection
  {
  
  [DataMember(Name = "Slash")]
  public Skill Slash { get; set; }
  
  [DataMember(Name = "Summon")]
  public Skill Summon { get; set; }
  
  public static object Deser(string path, Type toType)
  {
      var s = new DataContractSerializer(toType);
      using (FileStream fs = File.Open(path, FileMode.Open))
      {
          object s2 = s.ReadObject(fs);
          if (s2 == null)
              Console.WriteLine(@"  Deserialized object is null");
          else
              Console.WriteLine(@"  Deserialized type: {0}", s2.GetType());
          return s2;
      }
  }
  </code></pre>
  
  <p>It is called from another class through property Skills:</p>
  
  <pre><code>Skills = (SkillCollection)SkillCollection.Deser(
              Path.Combine(path, "Skills.xml"), 
              typeof(SkillCollection));
  </code></pre>
  
  <hr>
  
  <p><strong>Skill class:</strong></p>
  
  <pre><code>public class Skill
  {
      //Cast: time it takes to cast it
      [DataMember(Name = "Cast")]
      public float Cast { get; set; }
  
      //ReCast: cooldown period before player can cast it again
      [DataMember(Name = "ReCast")]
      public float ReCast { get; set; }
  
      [DataMember(Name = "MPCost")]
      public int MpCost { get; set; }
  
      public Timer Timer { get; private set; }
      public bool Ready { get; set; }
  
      public Skill()
      {
          Ready = true;
  
          Timer = new Timer { Interval = ReCast + 500, AutoReset = false };
          Timer.Elapsed += OnTimedEvent;
      }
  
      //Runs when recast is up
      private void OnTimedEvent(object source, ElapsedEventArgs e)
      {
          Ready = true;
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>XML File:</strong></p>
  
  <pre><code>&lt;Skills&gt;
    &lt;Slash&gt;
      &lt;Cast&gt;0.00&lt;/Cast&gt;
      &lt;ReCast&gt;60.00&lt;/ReCast&gt;
      &lt;MPCost&gt;0&lt;/MPCost&gt;
    &lt;/Slash&gt;
    &lt;Summon&gt;
      &lt;Cast&gt;5.98&lt;/Cast&gt;
      &lt;ReCast&gt;2.49&lt;/ReCast&gt;
      &lt;MPCost&gt;0&lt;/MPCost&gt;
    &lt;/Summon&gt;
  &lt;/Skills&gt;
  </code></pre>
  
  <hr>
  
  <p>Just so there is no confusion, my goal is to run the deserializer, and then have the SkillCollection class contain the two instances of Skill (Slash and Summon), and be able to access them separately through their properties.</p>
  
  <p>Thanks for any help / tips with debugging this.</p>