title: Why does XmlSerializer require types which inherit from IEnumerable to have an implementation of Add(System.Object)?
body: <p>I am using xml serialization but now came across a runtime error I haven't seen before.</p>
  
  <blockquote>
    <p>"To be XML serializable, types which
    inherit from IEnumerable must have an
    implementation of Add(System.Object)
    at all levels of their inheritance
    hierarchy. ImageEditor.EffectOptions
    does not implement Add(System.Object)"</p>
  </blockquote>
  
  <p>It seems a little weird to be forced to implement a method via runtime exception, rather than compile time error such as missing methods from implemented interfaces.</p>
  
  <p>Is this by design? Should this not be enforced via some sort of interface like <code>XmlSerializable</code>, etc?</p>
  
  <p>Other than this I am wondering if the serializer guarantees passing a value of the right type where I can just cast it to the type, which in my case is <code>EffectOption</code>.</p>
  
  <p>Or should I implement this <code>Add (object)</code> method to see if the object is of type <code>EffectOption</code> and if not throw an exception?</p>
  
  <p>I haven't implemented this <code>Add (object)</code> method before but my guess is it's safer to just cast it to <code>EffectOption</code> and add it to <code>EffectOptions</code> collection.</p>
  
  <p>EDIT: Here's the type itself:</p>
  
  <pre><code>public class EffectOptions : IEnumerable&lt;EffectOption&gt;
  {
      public List&lt;EffectOption&gt; Options { get; private set; }
  
      //IEnumerable methods
  }
  </code></pre>