title: XmlSerializer bug when serializing collection of collections without root element?
body: <p>This is a bit of a long question, but I've made it as terse as possible, so please bear with me. It looks to me like a bug in the <code>XmlSerializer</code> class but before I file it with Microsoft I'd like to see if there's anything I've missed, which is entirely possible.</p>
  
  <p>I'm attempting to generate the following XML as a representative case, which is essentially a collection of collections, but where the outer collection has additional elements:</p>
  
  <pre><code>&lt;Links&gt;
    &lt;Name /&gt;
    &lt;Group&gt;
      &lt;Link /&gt;
      &lt;Link /&gt;
    &lt;/Group&gt;
    &lt;Group&gt;
      &lt;Link /&gt;
      &lt;Link /&gt;
    &lt;/Group&gt;
  &lt;/Links&gt;
  </code></pre>
  
  <p>The serialization classes are as follows:</p>
  
  <pre><code>public class Link { }
  
  public class Links
  {
      public string Name { get; set; }
  
      [XmlElement("Group")]
      public Link[][] Groups { get; set; }
  }
  </code></pre>
  
  <p>And a simple test program to run it is as follows:</p>
  
  <pre><code>class Program
  {
      static void Main()
      {
          var serializer = new XmlSerializer(typeof(Links));
          var links = new Links { Name = "", Groups = new[] { 
              new[] { new Link(), new Link() }, 
              new[] { new Link(), new Link() } } };
          serializer.Serialize(Console.Out, links);
      }
  }
  </code></pre>
  
  <p>This employs the trick of <a href="https://stackoverflow.com/questions/639471/use-xml-serialization-to-serialize-a-collection-without-the-parent-node">using <code>XmlElement</code> to remove the parent node of the collection</a>, which should mean that no <code>&lt;Groups&gt;</code> element is emitted, and for each object contained in the outer array (which will be of type <code>Link[]</code>) a <code>&lt;Group&gt;</code> element should be emitted. However, at runtime, this gives the following exception from the <code>XmlSerializer</code>:</p>
  
  <blockquote>
    <p>Unable to generate a temporary class (result=1).
    error CS0030: Cannot convert type 'Link[][]' to 'Link[]'
    error CS0029: Cannot implicitly convert type 'Link[]' to 'Link[][]'</p>
  </blockquote>
  
  <p>My guess is that the serializer is for some reason attempting to flatten the collection, and thinks that the type contained in the outer array is <code>Link</code> rather than <code>Link[]</code> which causes the compilation failure of its serialization classes as the types don't match.</p>
  
  <p>What do you think? Is this a bug? And is there a workaround to generate the XML I'm after using the <code>XmlSerializer</code>?</p>