I have an issue with Serializing XML. I have an object with a DateTime property where the millisecond value is 990. However when I view the outputted string it is showing like this...
<ReadingsDateTime>2016-07-04T10:10:00.99Z</ReadingsDateTime>
The code used to convert this to xml is below, what is going on, I can not find a reason that this is happening.
string xml;
try
{
var serializer = new XmlSerializerFactory().CreateSerializer(typeof(T), xmlNamespace);
using (var memoryStream = new MemoryStream())
{
var settings = new XmlWriterSettings
{
Indent = false,
NamespaceHandling = NamespaceHandling.OmitDuplicates,
CloseOutput = false,
WriteEndDocumentOnClose = true,
};
using (var xmlWriter = XmlWriter.Create(memoryStream, settings))
{
serializer?.Serialize(xmlWriter, obj);
}
memoryStream.Seek(0, SeekOrigin.Begin);
using (var steamReader = new StreamReader(memoryStream))
{
xml = steamReader.ReadToEnd();
}
}
}
catch (Exception ex)
{
throw new ApplicationException("Unable to convert to XML from an object", ex);
}
return xml;