Document empty element behavior for DateTimeOffset and TimeSpan #56440
Labels
area-Serialization
documentation
Documentation bug or enhancement, does not impact product or test code
Milestone
Originally posted by @mconnew in #55101 (comment)
The gist is that for most primitive types, an empty element is impermissible. Nulls are represented with
xsi:nil
and 'default' values are implied by the abscence of the element. Empty elements result in exceptions for most types... except DateTimeOffset and TimeSpan.The reasoning for these two exceptions is because previous versions of XmlSerializer would unfortunately emit empty elements for these two types that it did not understand. When understanding of TimeSpan was added, the choice was made to not be noisy when encountering these empty elements which probably should not have been there in the first place, but they are, so lets just be graceful about it instead of throwing a tantrum. Or something. DateTimeOffset handling was added following the precedent of TimeSpan.
The argument could be made that we should throw exceptions when parsing these empty elements, as they likely are the result of an XmlSerializer that has silently lost data by writing an empty element. The flip side of that argument is that those empty elements aren't being written by the most recent XmlSerializer anymore, and being noisy about it is just going to annoy people who have already been working with a serializer that may or may not have been losing data... and they don't seem to mind. Sometimes "fixing a bug" is changing a behavior that people have come to depend on. I didn't make the TimeSpan change, but I think that is the principle being applied there.
Anyway, that's where we are. So we should document the special behavior of these two types.
The text was updated successfully, but these errors were encountered: