2

When xml element is empty, XmlSerializer throw exception

  • 1
    Possible duplicate of [Deserializing empty xml attribute value into nullable int property using XmlSerializer](http://stackoverflow.com/questions/1295697/deserializing-empty-xml-attribute-value-into-nullable-int-property-using-xmlseri) – Raidri May 03 '17 at 10:41

2 Answers2

1

Please try to add

<?xml version="1.0" encoding="UTF-8"?>

at the beginning of the xml file.

Dahico
  • 66
  • 2
  • 12
1

Unfortunately <StartRange></StartRange> isn't 'null'/'nil', it's an empty string. An empty string isn't a valid integer - hence the error.

You either need to change the XML to add the xsi:nil="true" attribute or change the definition to use a string for those properties (and parse them after the fact).

Charles Mager
  • 25,735
  • 2
  • 35
  • 45
  • @ShreyanshMakwana You can see [this question](http://stackoverflow.com/questions/1295697/deserializing-empty-xml-attribute-value-into-nullable-int-property-using-xmlseri) for the available options. I don't think you do what you want without some sort of workaround. – Charles Mager Mar 28 '17 at 11:36