title: Serialization error: there was an error reflecting type
body: <p>I have two classes: <code>ServiceTrigger</code> and <code>ServiceCalendar</code>.</p>
  
  <p>When I serialize <code>model.Triggers</code> I am getting an exception saying:</p>
  
  <blockquote>
    <p>Cannot serialize member 'yyy.ServiceTrigger.ServiceDaysOfWeek' of type<br>
    'System.Collections.Generic.IEnumerable`1[[yyyy.ServiceCalendar, yyy.ChangeAD, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]',<br>
        see inner exception for more details."}</p>
  </blockquote>
  
  <p>I have created an <code>IEnumerable&lt;ServiceTrigger&gt;</code>:</p>
  
  <pre><code>IEnumerable&lt;ServiceTrigger&gt; serviceTriggers = model.Triggers;
  XDocument xDoc = SerializationUtil.Serialize(model.Triggers);
  </code></pre>
  
  <p>First Class is like this:</p>
  
  <pre><code>[DataContract]
  public class ServiceTrigger
  {   
      [DataMember(Name = "triggerID")]
      public long TriggerID { get; set; }
  
      [DataMember(Name = "name")]
      public string Name { get; set; }
  
      [DataMember(Name = "dateStart")]
      public string DateStart { get; set; }
  
      [DataMember(Name = "code")]
      public string Code { get; set; }
  
      [DataMember(Name = "isActive")]
      public bool IsActive { get; set; }
  
      [DataMember(Name = "dateFrom")]
      public string DateFrom { get; set; }
  
      [DataMember(Name = "dateTo")]
      public string DateTo { get; set; }  
  
      [DataMember(Name = "currentState")]
      public string CurrentState { get; set; }
  
      [DataMember(Name = "daysOfWeek")]
      public IEnumerable&lt;ServiceCalendar&gt; ServiceDaysOfWeek { get; set; } 
  
      [DataMember(Name = "monthsOfYear")]
      public IEnumerable&lt;ServiceCalendar&gt; MonthsOfYear { get; set; }
  
      [DataMember(Name = "daysOfMonth")]
      public IEnumerable&lt;ServiceCalendar&gt; DaysOfMonth { get; set; } 
  }
  </code></pre>
  
  <p>Second Class is like this:       </p>
  
  <pre><code>[DataContract]
  public class Calendar
  {
      [DataMember(Name = "id")]
      public int Id { get; set; }
  
      [DataMember(Name = "name")]
      public string Name { get; set; }
  
      [DataMember(Name = "code")]
      public string Code { get; set; }
  
      [DataMember(Name = "isActive")]
      public bool IsActive { get; set; }
  )
  </code></pre>
  
  <p>My serialization class is like this:</p>
  
  <pre><code>public static class SerializationUtil
  {
      public static T Deserialize&lt;T&gt;(XDocument doc)
      {
          XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
  
          using (var reader = doc.Root.CreateReader())
          {
              return (T)xmlSerializer.Deserialize(reader);
          }
      }
  
      public static XDocument Serialize(this object obj)
      {
          XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
  
          XDocument doc = new XDocument();
          using (var writer = doc.CreateWriter())
          {
              xmlSerializer.Serialize(writer, obj);
          }
  
          return doc;
      }
  }
  </code></pre>