title: Custom object is serializable but not deserializable
body: <p>I get an object of a class with some properties by calling its own static function for an instance. If there is a XML file the object tries to load it and add its values to the instance itself. Then it will save the XML again in case there are missing options in the XML file.</p>
  
  <p>I created a small console app:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Collections;
  using System.IO;
  using System.Reflection;
  using System.Xml.Serialization;
  using System.Xml;
  
  namespace Test
  {
      public class Program
      {
          static void Main(string[] args)
          {
              TaskServerSettings s = TaskServerSettings.LoadNew();
          }
      }
  
      public class TaskServerSettings : IEqualityComparer
      {
          #region SETTINGS PROPERTIES
  
          public bool Enabled { get; set; }
          public int CheckInterval { get; set; }
  
          #endregion
  
          #region CONSTRUCTORS AND METHODS
  
          public TaskServerSettings()
          {
              this.init();
          }
  
          public TaskServerSettings(string settingsFile)
          {
              this.init();
              if (settingsFile != null)
              {
                  if (File.Exists(settingsFile))
                  {
                      this.Load(settingsFile);
                  }
                  this.Save(settingsFile);
                  }
          }
  
          private void init()
          {
              this.Enabled = true;
              this.CheckInterval = 5000;
          }
  
          public void Absorb(TaskServerSettings newSettings)
          {
              this.Enabled = newSettings.Enabled;
              this.CheckInterval = newSettings.CheckInterval;
          }
  
          public static TaskServerSettings LoadNew(string settingsFile = null)
          {
              if (settingsFile == null)
              {
                  settingsFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.TrimEnd('\\')) + @"\TaskServerSettings.xml";
              }
  
              return new TaskServerSettings(settingsFile);
          }
  
          public bool Load(string settingsFile = null)
          {
              if (settingsFile == null)
              {
                  settingsFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.TrimEnd('\\')) + @"\TaskServerSettings.xml";
              }
  
              if (!File.Exists(settingsFile))
              {
                  throw new FileNotFoundException("Could not find \"" + settingsFile + "\" to load settings.");
              }
  
              bool result = false;
              using (FileStream fs = new FileStream(settingsFile, FileMode.Open))
              {
                  XmlSerializer xs = new XmlSerializer(this.GetType());
                  if (!xs.CanDeserialize(XmlReader.Create(fs)))
                  {
                      throw new XmlException("\"" + settingsFile + "\" does not have a valid TaskServerSettings XML structure.");
                  }
                  //try
                  //{            // +- InvalidOperationException - Error in XML document (0,0).
                                 // v  The root element is missing.
                      this.Absorb(xs.Deserialize(fs) as TaskServerSettings);
                      result = true;
                  //}
                  //catch { }
              }
  
              return result;
          }
  
          public bool Save(string settingsFile = null)
          {
              if (settingsFile == null)
              {
                  settingsFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.TrimEnd('\\')) + @"\TaskServerSettings.xml";
              }
  
              bool result = false;
              using (FileStream fs = new FileStream(settingsFile, FileMode.Create))
              {
                  XmlSerializer xs = new XmlSerializer(this.GetType());
                  try
                  {
                      xs.Serialize(fs, this);
                      result = true;
                  }
                  catch { }
              }
  
              return result;
          }
  
          #endregion
  
          public bool Equals(TaskServerSettings settingsToCompare)
          {
              if (this.Enabled != settingsToCompare.Enabled ||
                  this.CheckInterval != settingsToCompare.CheckInterval)
              {
                  return false;
              }
              return true;
          }
          bool IEqualityComparer.Equals(object x, object y)
          {
              return x.Equals(y);
          }
          int IEqualityComparer.GetHashCode(object obj)
          {
              throw new NotSupportedException();
          }
      }
  }
  </code></pre>
  
  <p>Writing the object with its default property values in the first run works pretty good.
  The XML file looks like this then:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;TaskServerSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;Enabled&gt;true&lt;/Enabled&gt;
    &lt;CheckInterval&gt;5000&lt;/CheckInterval&gt;
  &lt;/TaskServerSettings&gt;
  </code></pre>
  
  <p>However, deserializing the same file on the second run causes the error when it tries to load the file on 
  <code>xs.Deserialize(fs) as TaskServerSettings</code>.</p>
  
  <pre><code>InvalidOperationException - Error in XML document (0,0).
  The root element is missing.
  </code></pre>
  
  <p>I already tried to avoid the static method and tried <code>new</code> as well as I already tried to remove the <code>IEqualityComparer</code> parent + the last three methods. Without success.</p>
  
  <p>I wonder, whats the cause of this error?</p>