title: Serializing a list of objects to XDocument
body: <p>I'm trying to use the following code to serialize a list of objects into XDocument, but I'm getting an error stating that "Non white space characters cannot be added to content
  "</p>
  
  <pre><code>    public XDocument GetEngagement(MyApplication application)
      {
          ProxyClient client = new ProxyClient();
          List&lt;Engagement&gt; engs;
          List&lt;Engagement&gt; allEngs = new List&lt;Engagement&gt;();
          foreach (Applicant app in application.Applicants)
          {
              engs = new List&lt;Engagement&gt;();
              engs = client.GetEngagements("myConnString", app.SSN.ToString());
              allEngs.AddRange(engs);
          }
  
          DataContractSerializer ser = new DataContractSerializer(allEngs.GetType());
  
          StringBuilder sb = new StringBuilder();
          System.Xml.XmlWriterSettings xws = new System.Xml.XmlWriterSettings();
          xws.OmitXmlDeclaration = true;
          xws.Indent = true;
  
          using (System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb, xws))
          {
              ser.WriteObject(xw, allEngs);
          }
  
          return new XDocument(sb.ToString());
      }
  </code></pre>
  
  <p>What am I doing wrong? Is it the <code>XDocument</code> constructor that doesn't take a list of objects? how do solve this?</p>