As part of #56711 partial support for DateOnly and TimeOnly has been added by @StephenMolloy to XmlSerializer and DataContractSerializer.
XElement, though, has not been changed to support it. The constructor of XElement accepts a value object that then gets turned into a string value that is special-cased against various types, including DateTime, DateTimeOffset, Timespan but currently not DateOnly or TimeOnly
https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XContainer.cs#L807-L824
As part of #56711 partial support for
DateOnlyandTimeOnlyhas been added by @StephenMolloy to XmlSerializer and DataContractSerializer.XElement, though, has not been changed to support it. The constructor of XElement accepts a value object that then gets turned into a string value that is special-cased against various types, including
DateTime,DateTimeOffset,Timespanbut currently notDateOnlyorTimeOnlyhttps://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XContainer.cs#L807-L824