title: C# Serialization skipping xsi:nil="true" if other attributes provided in custom object
body: <p>I'm not sure I've pinpointed the problem but it appears my C# XML Serialization is skipping adding the "xsi:nil='true' if there are either (and I'm not sure which or how to solve)</p>
  
  <ol>
  <li>Other attributes are provided or</li>
  <li>It's a custom object </li>
  </ol>
  
  <p>For example,</p>
  
  <pre><code>[System.Xml.Serialization.XmlElementAttribute("Custom", IsNullable = true)]
  public customDataType Custom
  {
          get { return this.privateCustomField; }
          set { this.privateCustomField= value; }
  }
  
  /// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.namespace.org")]
  public partial class customDataType
  {
      private string attrField;
      private string valueField;
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlAttributeAttribute()]
      public string AttrField
      {
          get { return this.attrField; }
          set { this.attrField= value; }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlTextAttribute()]
      public string Value
      {
          get { return this.valueField; }
          set { this.valueField = value;}
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Then in my class I create:</p>
  
  <pre><code>    Custom mycustom = new Custom();
      mycustom.AttrField = "7701003";
  </code></pre>
  
  <p>and that's it (I don't provide a <em>Value</em>). When I serialize my object, I get XML which looks like:</p>
  
  <p><strong>&lt;Custom AttrField="7701003"/></strong></p>
  
  <p>I'd like to see 
  <strong>&lt;Custom xsi:nil="true" AttrField="7701003"/></strong></p>
  
  <p>That is, I don't get the nil="true" added. I"m not sure because of the custom data type (instead of int or string as I've seen online) or the fact there's an attribute.</p>
  
  <p>The classes I'm using were created from an XSD using XSD.exe 4.0.30319.</p>
  
  <p>Thanks!</p>