Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

XmlSerialization and the constructor assignment

$
0
0
I have a complex XML data and i am deserializing it into the object named "Customer" by using XmlSerializer.

    public partial class StringType
    {
      private string valueField;
      private string priorValueField;
    
      [System.Xml.Serialization.XmlAttributeAttribute()]
      public string Value
      {
         get {return this.valueField; }
         set { this.valueField = value; }
      }
    
     public string PriorValue
      {
         get {return this.priorValueField; }
         set { this.priorValueField = value; }
      }
    }
    
    
    public class Customer
    {
      public Customer()
      {
         this.nameField.PriorValue = "XXX"; // This line is the issue
      }
    
      private StringType nameField;
    
      [System.Xml.Serialization.XmlAttributeAttribute()]
      public string Name
      {
         get {return this.nameField; }
         set { this.nameField = value; }
      }  
    
    }

When the destabilization happens, the constructor of the "Customer" class is not assigning any values due to the type of "Name" property which is a type of another class "StringType". I get "Null reference" exception. However, if i change the type of the "Name" property to .NET string type, i am able to assign the value successfully on the constructor during xml deserializion. Can anyone explain me why it fails on the constructor assignment when the type of the"Name" property is another class?

Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>