0

Given a well-formed but invalid xml. Defining invalid as an xml with an illegal value, for example Date in an incorrect format.

With XmlSerializer, is it possible continue the deserialization of an xml in case of errors with some properties?

s.demuro
  • 399
  • 2
  • 15
  • When you get an error the string textResponse is not XML. You would need to parse the string textResponse for error condition. – jdweng Jun 14 '23 at 13:39
  • edited for clarity and made more generic at the same time – s.demuro Jun 14 '23 at 17:35
  • I don't think there is any way to do this with `XmlSerializer`, it's designed to be intolerant of XML that violates the schema of the deserialized types. Notably, its only documented [events](https://learn.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlserializer?view=net-7.0#events) are for unknown nodes, elements and attributes, or unreferenced SOAP objects. There's no event for a deserialization error. – dbc Jun 14 '23 at 18:53
  • Similar questions were never answered, e.g. [Deserializing xml that contains an invalid data type](https://stackoverflow.com/q/12820776), [When using XmlSerializer.Serialize is it possible to discard elements that throw errors during serialization?](https://stackoverflow.com/q/66142455), [How can I skip objects in XML Deserialization that throw errors?](https://stackoverflow.com/q/64929205), [How to ignore exceptions while deserializing xml to an object](https://stackoverflow.com/q/67311716). – dbc Jun 14 '23 at 18:54

0 Answers0