title: XmlAttribute/XmlText cannot be used to encode complex type
body: <p>I want to serialize a class <code>Ticket</code> into xml. I get the error :"XmlAttribute/XmlText cannot be used to encode complex type" because of my customfield class. </p>
  
  <p>This is how the xml for customfields should look like ( the attribute array is nesseray but I don't understand how to create it):</p>
  
  <pre><code>&lt;custom_fields type="array"&gt;
  &lt;custom_field name="Standby Reason" id="6"&gt;
  &lt;value/&gt;
  &lt;/custom_field&gt;
  &lt;custom_field name="Close Date" id="84"&gt;
  </code></pre>
  
  <p><strong>Class Ticket</strong></p>
  
  <pre><code>public class Ticket
  {
      [XmlElement("custom_fields")]
      public CustomFields Custom_fields { get; set; }
  </code></pre>
  
  <p><strong>Class CustomFields</strong></p>
  
  <pre><code>[Serializable]
  public class CustomFields
  {
      [XmlAttribute("array")]
      public List&lt;CustomField&gt; custom_field { get; set; }
  </code></pre>
  
  <p><strong>Class CustomField</strong></p>
  
  <pre><code>[Serializable]
  public class CustomField
  {
      [XmlIgnore]
      public string Name { get; set; }
  
      [XmlElement]
      public int Id { get; set; }
  
      [XmlElement]
      public string Value { get; set; }
  </code></pre>
  
  <p><strong>Serialize Method</strong></p>
  
  <pre><code>public string Serialize(object obj)
  {
      var nsSerializer = new XmlSerializerNamespaces();
      nsSerializer.Add(String.Empty, String.Empty);
  
      var serializer = new XmlSerializer(typeof(Ticket), String.Empty);
  
      using (StringWriter writer = new StringWriter())
      {
          ExtendedXmlTextWriter xmlTextWriter = new ExtendedXmlTextWriter(writer);
          serializer.Serialize(xmlTextWriter, obj, nsSerializer);
  
          //return writer.ToString();
  
          XElement root = new XElement("custom_fields", new XAttribute("type", "array"),
              new XElement("custom_field",
                  new XAttribute("name", "Standby Reason"),
                  new XAttribute("id", 6)
                  ), new XElement("value"),
                      new XElement("custom_field",
                          new XAttribute("name", "Close Date"),
                          new XAttribute("id", 84)
                          )
                          );
  
          return (writer.ToString() + root.ToString());
      }
  </code></pre>