Morning, we've had this a lot but the answers I've found do not appear to work.
C# 3.0, .Net 3.5, XML Serialization into a nullable DateTime property does not work with an empty string. The exception is thrown before the internals of the property, when the XmlSerializer attempts to use DateTime.ParseExact (when I use a DataType="date"
value) and just complains that it is not a valid DateTime format when I do not.
A few of the various combinations of signature that I have used are below but am I fundamentally wrong that empty strings should be classed as null values? I bet at the end of this the conclusion will be: "if you have a value then pass a populated
element in the xml, if you don't then don't pass that element at all" or "if you have no value you can still send the element so long as it has the
xsi:nil attribute" .
A few combinations:
[XmlElement("foo")]
DateTime Foo {get; set;}
[XmlElement("foo")]
DateTime? Foo {get; set;}
[XmlElement("foo", DataTime="date")] // yes I just want the date part
DateTime? Foo {get; set;}
[XmlElement("foo", IsNullable=true)] // I believe Bet that this only makes a difference serialising to xml not from xml
DateTime Foo {get; set;}
<CutMoreCombinations />
The XML I'm sending is "<foo />"
Thanks
Andy