title: C#: To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object)
body: <p>I have the following code:</p>
  
  <pre><code>private static string FindAppointmentsAsXmlString(CalendarView calendar, ExchangeService serv)
  {
      FindItemsResults&lt;Appointment&gt; appointments = serv.FindAppointments(WellKnownFolderName.Calendar, calendar);
  
      var serializer = new XmlSerializer(appointments.GetType());
      var writer = new StringWriter();
  
      try
      {
          serializer.Serialize(writer, appointments);
          Console.WriteLine(writer.GetStringBuilder().ToString());
          Console.ReadLine();
      }
      catch (Exception ex) 
      {
          Console.WriteLine(ex);
          Console.ReadLine();
      }
  
      return writer.GetStringBuilder().ToString();
  }
  </code></pre>
  
  <p>When initializing serializer, I get the exception:</p>
  
  <p><strong>To be XML serializable, types which inherit from IEnumerable must have an
  implementation of Add(System.Object) at all levels of their inheritance hierarchy.</strong></p>
  
  <p><strong>Microsoft.Exchange.WebServices.Data.FindItemsResults does not implement Add(System.Object).</strong></p>
  
  <p>I've searched around, and I've come to the conclusion that I have to add a public Add(Object obj) method. Now I'm not really sure what this method should contain or when it is called, can anyone point me in the right direction? Does the <code>Add</code> method need to manually add each appointment?</p>
  
  <p>Some links I found helpful:
  <a href="https://stackoverflow.com/questions/4147923/to-be-xml-serializable-types-which-inherit-from-icollection-must-have-an-implem">here</a>
  <a href="https://stackoverflow.com/questions/5172757/why-does-xmlserializer-require-types-which-inherit-from-ienumerable-to-have-an-i">here</a></p>
  
  <p>Much appreciated.</p>