title: XML deserialization in C# returns an empty object
body: <p>I have a problem here about deserialization. I have a XML file that I need to deserialize into a class that I get from a Service reference. I know how to deserialize a XML file, but when I try to deserialize this file I get  a empty class object. I don't understand why is it doing that.</p>
  
  <p>The XML files content looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;&lt;iVAZFile xmlns="http://www.v.lt/c/i/iv"&gt;
  &lt;FileDescription&gt;
  &lt;FileVersion&gt;i1.3.3&lt;/FileVersion&gt;
  &lt;FileDateCreated&gt;2016-11-07T12:28:32&lt;/FileDateCreated&gt;
  &lt;SoftwareCompanyName&gt;otechnika&amp;quot;&lt;/SoftwareCompanyName&gt;
  &lt;SoftwareName&gt;Eita&lt;/SoftwareName&gt;
  &lt;SoftwareVersion&gt;2016.9&lt;/SoftwareVersion&gt;
  &lt;CreatorRegistrationNumber&gt;123060356&lt;/CreatorRegistrationNumber&gt;
  &lt;/FileDescription&gt;
  &lt;/iVAZFile&gt;
  </code></pre>
  
  <p>The class looks like this:</p>
  
  <pre><code> [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1590.0")]
      [System.SerializableAttribute()]
      [System.Diagnostics.DebuggerStepThroughAttribute()]
      [System.ComponentModel.DesignerCategoryAttribute("code")]
      [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.v.lt/c/i/iv")]
      public partial class FileDescription : object, System.ComponentModel.INotifyPropertyChanged {
  
          private string fileVersionField;
  
          private System.DateTime fileDateCreatedField;
  
          private string softwareCompanyNameField;
  
          private string softwareNameField;
  
          private string softwareVersionField;
  
          private ulong creatorRegistrationNumberField;
  
          public FileDescription() {
              this.fileVersionField = "iVAZ1.3.3";
          }
  
          /// &lt;remarks/&gt;
          [System.Xml.Serialization.XmlElementAttribute(Order=0)]
          public string FileVersion {
              get {
                  return this.fileVersionField;
              }
              set {
                  this.fileVersionField = value;
                  this.RaisePropertyChanged("FileVersion");
              }
          }
  
          /// &lt;remarks/&gt;
          [System.Xml.Serialization.XmlElementAttribute(Order=1)]
          public System.DateTime FileDateCreated {
              get {
                  return this.fileDateCreatedField;
              }
              set {
                  this.fileDateCreatedField = value;
                  this.RaisePropertyChanged("FileDateCreated");
              }
          }
  
          /// &lt;remarks/&gt;
          [System.Xml.Serialization.XmlElementAttribute(Order=2)]
          public string SoftwareCompanyName {
              get {
                  return this.softwareCompanyNameField;
              }
              set {
                  this.softwareCompanyNameField = value;
                  this.RaisePropertyChanged("SoftwareCompanyName");
              }
          }
  
          /// &lt;remarks/&gt;
          [System.Xml.Serialization.XmlElementAttribute(Order=3)]
          public string SoftwareName {
              get {
                  return this.softwareNameField;
              }
              set {
                  this.softwareNameField = value;
                  this.RaisePropertyChanged("SoftwareName");
              }
          }
  
          /// &lt;remarks/&gt;
          [System.Xml.Serialization.XmlElementAttribute(Order=4)]
          public string SoftwareVersion {
              get {
                  return this.softwareVersionField;
              }
              set {
                  this.softwareVersionField = value;
                  this.RaisePropertyChanged("SoftwareVersion");
              }
          }
  
          /// &lt;remarks/&gt;
          [System.Xml.Serialization.XmlElementAttribute(Order=5)]
          public ulong CreatorRegistrationNumber {
              get {
                  return this.creatorRegistrationNumberField;
              }
              set {
                  this.creatorRegistrationNumberField = value;
                  this.RaisePropertyChanged("CreatorRegistrationNumber");
              }
          }
  
          public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
  
          protected void RaisePropertyChanged(string propertyName) {
              System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
              if ((propertyChanged != null)) {
                  propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
              }
          }
      }
  </code></pre>
  
  <p>And the method that I use to populate the class:</p>
  
  <pre><code>using (MemoryStream memoryStream = new MemoryStream())
              {
                  using (BinaryWriter binWriter = new BinaryWriter(memoryStream, Encoding.UTF8))
                  {
                      string filep = File.ReadAllText("test.xml");
                      binWriter.Write(filep);
                      memoryStream.Seek(2, SeekOrigin.Begin);
                      using (StreamReader streamReader = new StreamReader(memoryStream))
                      {
                          using (XmlReader reader = XmlReader.Create(streamReader))
                          {
                              XmlRootAttribute xRoot = new XmlRootAttribute();
                              xRoot.ElementName = "FileDescription";
                              xRoot.IsNullable = false;
                              XmlSerializer serializer = new XmlSerializer(typeof(FileDescription),xRoot);
                              FileDescription dsc = new FileDescription();
                              dsc=(FileDescription)serializer.Deserialize(reader);
                          }
                       }
                   }
                 }
  </code></pre>
  
  <p>A few additional comment to say what I also tried:</p>
  
  <ol>
  <li>I made my own class that looked the same as the one from the service reference and added a new parameter <code>[XmlRoot(ElementName="FileDescription"),XmlType("FileDescription")]</code>
  then the deserilization worked on my class.</li>
  <li>Tried adding values by hand without deserilization that worked fine as well so there's no problem with the service code.</li>
  <li>Also when I'm deserializing the xml I remove <code>&lt;iVAZFile xmlns="http://www.v.lt/c/i/iv"&gt;</code> and <code>&lt;/iVAZFIle&gt;</code> because when deserializing it will throw and exception was not expecting .</li>
  </ol>
  
  <p>And lastly a few words I cannot change the service reference class and I need to use that class for later so I cannot make my own.</p>