How to use XmlInclude to specify types dynamically?
<p>I have these classes which I use:</p>

<pre><code>namespace defaultNamespace
{
    ...
    public class DataModel
    {
    }
    public class Report01
        {get; set;}
    public class Report02
        {get; set;}
}
</code></pre>

<p>And I have a method that creates the XML below.</p>

<pre><code>public XmlDocument ObjectToXml(object response, string OutputPath)
{
    Type type = response.GetType();
    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(type);
    MemoryStream stream = new MemoryStream();
    StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
    serializer.Serialize(writer, response);
    XmlDocument xmldoc = new XmlDocument();
    stream.Position = 0;
    StreamReader sReader = new StreamReader(stream);
    xmldoc.Load(sReader);
    stream.Position = 0;
    string tmpPath = OutputPath;
    while (File.Exists(tmpPath))
    {
        File.Delete(tmpPath);
    }
    xmldoc.Save(tmpPath);
    return xmldoc;
}
</code></pre>

<p>And I have two lists that has a Report01 and Report02 object.</p>

<pre><code>List&lt;object&gt; objs = new List&lt;object&gt;();
List&lt;object&gt; objs2 = new List&lt;object&gt;();

Report01 obj = new Report01();
obj.prop1 = "aa";
obj.prop2 = "bb";
objs.Add(obj);

Report02 obj2 = new Report02();
obj2.prop1 = "cc";
obj2.prop2 = "dd";
objs2.Add(obj2);
</code></pre>

<p>When I try to create the XML like this:</p>

<pre><code>ObjectToXml(objs, "c:\\12\\objs.xml");
ObjectToXml(objs2, "c:\\12\\objs2.xml");
</code></pre>

<p>I see this exception:</p>

<blockquote>
  <p>The type "Report01(or Report02)" was not expected. Use the XmlInclude
  or SoapInclude attribute to specify types that are not known
  statically.</p>
</blockquote>

<p>How can I solve this problem?</p>