none
[E2010] [EWS] [C#] Reading email notifications throws XML exception when illegal character is encountered RRS feed

  • Question

  • Exchange Version: Exchange 2010 SP1

    API Name: Exchange Web Services Managed API

    API Version: 14.0.0.0

    IDE: Visual Studio 2008 Professional

    Targeted Features: Reading emails

    Scenario Description:

    We have an application that uses a StreamingSubscriptionConnection to reads every email that gets sent to a particular mailbox. The issue I'm running into several times a day during development I get the exception {"'{square character}', hexadecimal value 0x1F, is an invalid character. Line 1, position 1."}.

    Here is the stack trace:

       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)

    How can I safely read every email with EWS regardless of it's contents?

    Wednesday, July 27, 2011 1:17 PM

All replies

  • Hi Michael,

    please enable tracing on the ExchangeService instance. This might give you a clue about the data that is being returned from the server. Line 1, column 1 seems to indicate some sort of byte-order mark for the text encoding of the whole XML document returned.

    "michaelc.h1" wrote in message news:22863099-1d93-47ac-a11b-08c6bf7facea@communitybridge.codeplex.com...

    Exchange Version: Exchange 2010 SP1

    API Name: Exchange Web Services Managed API

    API Version: 14.0.0.0

    IDE: Visual Studio 2008 Professional

    Targeted Features: Reading emails

    Scenario Description:

    We have an application that uses a StreamingSubscriptionConnection to reads every email that gets sent to a particular mailbox. The issue I'm running into several times a day during development I get the exception {"'{square character}', hexadecimal value 0x1F, is an invalid character. Line 1, position 1."}.

    Does this happen for specific emails?

    Kind regards,
    Henning

    Here is the stack trace:
       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)

    How can I safely read every email with EWS regardless of it's contents?

    Wednesday, July 27, 2011 3:55 PM
  • Thanks for the reply.

    I have added tracing to `ExchangeService`. Can't seem to reproduce the issue at this point in time.

    I will post back once the exception gets thrown again.

    Thank you.

    Thursday, July 28, 2011 5:26 PM
  • This is the full stacktrace of the exception as well as the garbage data EWS is returning.

    Any ideas?

    Friday, August 5, 2011 12:58 PM
  • Hi Michael,

    this is really strange. Can you please use Fiddler (http://www.fiddler2.com/fiddler2/) to capture the entire traffic? This might give a clue on what's going on here. You need to enable HTTPS decryption once you installed fiddler. And you need to accept any server certificate in your application to get this to work.

    Kind regards,
    Henning

    Tuesday, August 9, 2011 8:41 PM