title: Serializing an arraylist in C#
body: <p>I have a class that contains a number of standard fields and an arraylist.</p>
  
  <p>Is there any way to serialize the class using an XmlSerializer?</p>
  
  <p>Attempts so far result in an error message saying:</p>
  
  <pre>Unhandled Exception: System.InvalidOperationException: There was an error
  generating the XML document. ---> System.InvalidOperationException: The type
  XMLSerialization.DataPoints was not  expected. Use  the XmlInclude or
  SoapInclude attribute  to specify types that are not known statically.</pre>
  
  <p>Some cut-down representations of the classes are shown below:</p>
  
  <pre><code>public class StationData
  {
    private DateTime _CollectionDate;
    private string _StationID;
    private ArrayList _PolledData;
  
    public StationData()
    {
    }
    public DateTime CollectionDate
    {
      get { return _CollectionDate; }
      set { _CollectionDate = value; }
    }
    public string StationID
    {
      get { return _StationID; }
      set { _StationID = value; }
    }
    [XmlInclude(typeof(DataPoints))]
    public ArrayList PolledData
    {
      get { return _PolledData; }
      set { _PolledData = value; }
    }
  }
  
  public class DataPoints
  {
    private string _SubStationID;
    private int _PointValue;
  
    public DataPoints
    {
    }
    public string SubStationID
    {
      get { return _SubStationID; }
      set { _SubStationID = value; }
    }
    public int PointValue
    {
      get { return _PointValue; }
      set { _PointValue = value; }
    }
  }
  </code></pre>