简体   繁体   中英

How can I catch this XmlException thrown from third party library?

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM