Wednesday, 11 September 2013

Deserialization Error attempting to parse embedded document in XML

Deserialization Error attempting to parse embedded document in XML

I have code that accepts a string of XML and deserializes it into a .NET
object. The string includes a few Base64 encoded documents of modestly
large size.
In various testing internally and with an external vendor I've received
200-300 of these without issue, but generally with smaller files (100K -
2MB). Receiving a few larger files, I've run into the following on three
of seven attempts with embedded docs over 7MB.
There is an error in XML document (168, 3735935).
Message:
An error occurred while parsing EntityName. Line 168, position 3735935.
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle)
The code itself is pretty straightforwrd:
var searchResult = new XmlSerializer(typeof(MyType));
var resultObject =
(MyType)searchResult.Deserialize(StringToStream(SourceXml));
My original thought was memory--not that 10MB is massive--but might
explain the intermittent issues and that at least in one case resubmitting
the same worked. But another failed on the same byte in multiple runs.
Has anyone encountered (and hopefully) solved this?

No comments:

Post a Comment