title: XMLSerialize an ObservableCollection
body: <p>I am having a problem in the xml serialization of observable collection.</p>
  
  <p>Here is what I am serializing:</p>
  
  <pre><code>public enum Status { Pending, Active, Completed, Cancelled }
  
  public abstract class Entity : INotifyPropertyChanged
  {
      ...
  }
  
  public class UserStory : Entity
  {
      public uint StoryID { get; set; }
      public Status Status { get; set; }
      ...
      public ObservableCollection&lt;Task&gt; Tasks { get; set; }
  }
  
  public class Task : Entity
  {
      public uint TaskID { get; set; }
      ...
  }
  </code></pre>
  
  <p>Here is how I serialize it:</p>
  
  <pre><code>public static void SerializeObjectToXML&lt;T&gt;(T item, string FilePath)
  {
      XmlSerializer xs = new XmlSerializer(typeof(T));
      using (StreamWriter wr = new StreamWriter(FilePath))
      {
          xs.Serialize(wr, item);
      }
  }
  
  public class Main()
  {
      ObservableCollection&lt;UserStory&gt; UserStories { get; set; }
  
      void Main()
      {
          ...
          ObservableCollection&lt;object&gt; Document = new ObservableCollection&lt;object&gt;();
          Document.Add(UserStories);
          SerializeObjectToXML&lt;ObservableCollection&lt;object&gt;&gt;(Document , "...");
          ...
      }
  }
  </code></pre>
  
  <p>But an error occur in the <code>xs.Serialize(wr, item);</code> line saying:</p>
  
  <blockquote>
    <p><strong>InvalidOperation Exception</strong>: There was an error generating the XML document.
    <em>Inner Exception</em>: The type ScrumPresentor.ObservableCollection`1[[ScrumPresentor.UserStory,
    ScrumPresentor, Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=null]] may not be used in this context.</p>
  </blockquote>
  
  <p>I am using Visual Studio 2010, WPF application in .NET 4.0.</p>