title: XmlSerializer & Paste XML as classes
body: <p>I have a web service that is returning some xml.  There is no corresponding xsd.</p>
  
  <p>I used the Paste Special -> Paste XML as classes functionality in visual studio to generate the classes to use with <code>XmlSerializer</code>:</p>
  
  <p>When the code executes the line</p>
  
  <pre><code>--&gt; XmlSerializer xmlSerialize = new XmlSerializer(typeof(table)); &lt;--
      table t = (table)xmlSerialize.Deserialize(new StringReader(soapResult));
  </code></pre>
  
  <p>it throws an exception:</p>
  
  <pre><code>System.InvalidOperationException: 'Unable to generate a temporary class (result=1).
  error CS0030: Cannot convert type 'string[]' to 'string'
  error CS0029: Cannot implicitly convert type 'string' to 'string[]'
  </code></pre>
  
  <p>The generated classes look like so:</p>
  
  <pre><code>// NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0.
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
      [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
      public partial class table
      {
  
          private string[] labelField;
  
          private string[] classnameField;
  
          private string[] datatypeField;
  
          private string[][] rowField;
  
  
          /// &lt;remarks/&gt;
          [System.Xml.Serialization.XmlArrayItemAttribute("d", IsNullable = false)]
          public string[] label
          {
              get
              {
                  return this.labelField;
              }
              set
              {
                  this.labelField = value;
              }
          }
  
          /// &lt;remarks/&gt;
          [System.Xml.Serialization.XmlArrayItemAttribute("d", IsNullable = false)]
          public string[] classname
          {
              get
              {
                  return this.classnameField;
              }
              set
              {
                  this.classnameField = value;
              }
          }
  
          /// &lt;remarks/&gt;
          [System.Xml.Serialization.XmlArrayItemAttribute("d", IsNullable = false)]
          public string[] datatype
          {
              get
              {
                  return this.datatypeField;
              }
              set
              {
                  this.datatypeField = value;
              }
          }
  
          /// &lt;remarks/&gt;
          [System.Xml.Serialization.XmlArrayItemAttribute("d", typeof(string), IsNullable = true)]
          public string[][] row
          {
              get
              {
                  return this.rowField;
              }
              set
              {
                  this.rowField = value;
              }
          }
      }
  </code></pre>
  
  <p>The problem is with the row field, as the others work ok.
  If I change</p>
  
  <pre><code>[System.Xml.Serialization.XmlArrayItemAttribute("d", typeof(string), IsNullable = true)]
  </code></pre>
  
  <p>to</p>
  
  <pre><code>[System.Xml.Serialization.XmlArrayItemAttribute("d", typeof(string[]), IsNullable = true)]
  </code></pre>
  
  <p>the error goes away, but my object just has an array of empty string arrays.</p>
  
  <p>The XML data being deserialized (condensed for simplicity) looks like this</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;table&gt;
     &lt;label&gt;
        &lt;d&gt;JobDefinition.SearchName&lt;/d&gt;
        &lt;d&gt;Job.JobDefinition&lt;/d&gt;
     &lt;/label&gt;
     &lt;classname&gt;
        &lt;d&gt;JobDefinition.SearchName&lt;/d&gt;
        &lt;d&gt;Job.JobDefinition&lt;/d&gt;
     &lt;/classname&gt;
     &lt;datatype&gt;
        &lt;d&gt;String&lt;/d&gt;
        &lt;d&gt;obj.JobDefinition&lt;/d&gt;
     &lt;/datatype&gt;
     &lt;row&gt;
        &lt;d&gt;AB_DEFG_QA_RUN&lt;/d&gt;
        &lt;d&gt;A_JOB_Run&lt;/d&gt;
     &lt;/row&gt;
     &lt;row&gt;
        &lt;d&gt;AB_DEFG_QA_RUN&lt;/d&gt;
        &lt;d&gt;B_JOB_Run&lt;/d&gt;
     &lt;/row&gt;
  &lt;/table&gt;
  </code></pre>