0

I'm using the Exchange Web Services managed API and about once a day it throws an XmlException that I have no idea how to catch. Here are the exception details.

System.Xml.XmlException was unhandled
  Message="'', hexadecimal value 0x1F, is an invalid character. Line 1, position 1."
  Source="System.Xml"
  LineNumber=1
  LinePosition=1
  SourceUri=""
  StackTrace:
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
       at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
       at System.Xml.XmlTextReaderImpl.ThrowInvalidChar(Int32 pos, Char invChar)
       at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
       at System.Xml.XmlTextReaderImpl.ParseText()
       at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
       at System.Xml.XmlTextReaderImpl.Read()
       at Microsoft.Exchange.WebServices.Data.EwsXmlReader.Read()
       at Microsoft.Exchange.WebServices.Data.EwsXmlReader.Read(XmlNodeType nodeType)
       at Microsoft.Exchange.WebServices.Data.EwsXmlReader.InternalReadElement(XmlNamespace xmlNamespace, String localName, XmlNodeType nodeType)
       at Microsoft.Exchange.WebServices.Data.EwsXmlReader.ReadStartElement(XmlNamespace xmlNamespace, String localName)
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadResponse(EwsServiceXmlReader ewsXmlReader)
       at Microsoft.Exchange.WebServices.Data.HangingServiceRequestBase.ParseResponses(Object state)
       at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
  InnerException: 

From the stacktrace I don't see anything that would allow me to catch and fix the issue.

How can I catch this?

1 Answers1

2

Your XML library doesn't support the 0x1F char, which is the unit separator char.

What you can do is escape all occurrences of this specific char before your stream/XML file/whatever/ is processed by your XML library. See How do I escape unicode character 0x1F in xml?

See allowed character ranges for XML 1.1.

Community
  • 1
  • 1
ken2k
  • 48,145
  • 10
  • 116
  • 176
  • My apologies on not being very clear. The issue is caused by the EWS library parsing the XML returned by Exchange *without* sanitizing it. Because all of this is done within the library I don't know how to catch it. – user1480458 Jul 13 '12 at 14:15