简体   繁体   English

如何捕获从第三方库抛出的XmlException?

[英]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. 我正在使用Exchange Web服务托管API,大约每天抛出一个我不知道如何捕获的XmlException 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. 您的XML库不支持0x1F char,它是单位分隔符 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. 您可以做的是您的流/ XML文件/ XML库处理的任何/ 之前转义所有此特定char。 See How do I escape unicode character 0x1F in xml? 请参阅如何在xml中转义unicode字符0x1F?

See allowed character ranges for XML 1.1 . 请参阅XML 1.1的允许字符范围

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我无法捕获第三方库引发的异常? - Why I can't catch an exception thrown from third party library? 如何捕获第三方库中未等待的任务引发的异常? - How to catch exception thrown by a task that's not awaited in a third party library? 如何阻止第三方调用某些方法? - How can I prevent a third party from calling certain methods? 从第三方组件抛出StackOverflowException时如何中断我的源代码? - How to break at my source code when StackOverflowException is thrown from third party component? XmlException从配置文件中抛出 - XmlException getting thrown from config file 如何在不使用第三方库的情况下从HTML提取文本? - How I can extract text from HTML without using third-party libraries? 如何吞下catch块中抛出的异常? - How can I swallow an exception that is thrown inside a catch block? 如何在第三方注册中找到客户端IP? - How can I find client IP on Third-party registration? 如何使用强名称签名第三方COM dll - How can I sign a third party COM dll with strong name 3层(项目):如何从第一层引发异常并在第三层中捕获它 - 3 layers(Projects): How can I throw an exception from first layer and catch it in the third
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM