title: How to Serialize ICollection<T> as List<T> to Xml?
body: <p>I am trying to dynamically serialize a List to Xml.
  I am able to do so, as long I do not have a ICollection as a property of T.</p>
  
  <p>I would like to dynamically overwrite the ICollection type into List before I write it to Xml.</p>
  
  <p>This is what I have so far. </p>
  
  <pre><code>List&lt;-XmlElementAttribute-&gt; attrToConvertList = new List&lt;-XmlElementAttribute-&gt;();
  
  foreach (var propertyInfo in typeof(T).GetProperties())
  {
      if (propertyInfo.PropertyType.Name == "ICollection`1")
      {
          XmlElementAttribute attrToConvert = new XmlElementAttribute();
          attrToConvert.ElementName = propertyInfo.Name;
          attrToConvert.Type = typeof(List&lt;&gt;);
          attrToConvert.Type = attrToConvert.Type.MakeGenericType(propertyInfo.PropertyType.GetGenericArguments()[0]);
          attrToConvertList.Add(attrToConvert);
      }
  }
  XmlAttributeOverrides overrides = new XmlAttributeOverrides();
  XmlAttributes attributesToConvert = new XmlAttributes();
  
  foreach (var xmlElementAttribute in attrToConvertList)
      attributesToConvert.XmlElements.Add(xmlElementAttribute);
  
  overrides.Add(typeof(T), attributesToConvert);
  XmlSerializer serializer = new XmlSerializer(typeof(List&lt;T&gt;), overrides);
  </code></pre>
  
  <p>I get the error that I cannot serialize the type ICollection because it is an interface.
  I was under the impression that what I was doing with the XmlAttributeOverrides was supposed to overwrite the ICollection to the type List.</p>