Deserialization have incorrect behavior

78 Views Asked by At

I'm try deserialize object, which contains of tag like <A />.That is why the deserializable object have a field with Null value (that is incorrect behavior). If this tag raplace to tag like <A></A>, the deserialization have a correct result. Although, if problem tag transfer to the end of XML document, then also the deserialization have a correct result. That is this?

public static T SerializeFileToObject<T>(string path) 
{ 
  T result; 
  using(TextReader textReader = new StreamReader(path)) 
  {
    var deserializer = new XmlSerializer(typeof(T)); 
    result = (T)deserializer.Deserialize(textReader); 
  } 
  return result; 
}

In resultutive object have propeties protocolDescription and versionDescription with Null value both. Expected behavior: protocolDescription == null , versionDescription == ""

[System.SerializableAttribute()]
    public partial class protocolVersion {

        private protocolVersionProtocolInfo protocolInfoField;

        private protocolVersionPrerequisites prerequisitesField;

        private protocolVersionOperations operationsField;

        /// <remarks/>
        public protocolVersionProtocolInfo protocolInfo {
            get {
                return this.protocolInfoField;
            }
            set {
                this.protocolInfoField = value;
            }
        }

        /// <remarks/>
        public protocolVersionPrerequisites prerequisites {
            get {
                return this.prerequisitesField;
            }
            set {
                this.prerequisitesField = value;
            }
        }

        /// <remarks/>
        public protocolVersionOperations operations {
            get {
                return this.operationsField;
            }
            set {
                this.operationsField = value;
            }
        }
    }
<?xml version="1.0" encoding="utf-8"?>
<protocolVersion>
  <protocolInfo>
    <protocolDescription><![CDATA[]]></protocolDescription>
    <versionDescription />
  </protocolInfo>
  <prerequisites>
    <methods>
      <liquidHandler />
      <detector />
    </methods>
    <plateSets>
      <plateSet name="1" shouldExist="true" format="1" maxrow="11" maxcol="11" />
    </plateSets>
  </prerequisites>
  <operations initialPlateSet="1">
    <addCompound name="1" plateSet="1">
      <wells>
        <compoundRange>
          <from row="D" col="5" />
          <to row="H" col="14" />
          <volume value="0" unit="UL" />
          <concentration value="0" unit="NM" />
          <dilution>1</dilution>
        </compoundRange>
      </wells>
      <description><![CDATA[]]></description>
    </addCompound>
  </operations>
</protocolVersion>
0

There are 0 best solutions below