none
EWS API 2.0 throws "TimeZoneConversionException" when trying to save MIMEContent of email item RRS feed

  • Question

  • I am trying to save an email from my mailbox .eml file (as a byte array into a SQL database).

    However when running the following line of code, a 'TimeZoneConversionException' is thrown.

    email.Load(new PropertySet(ItemSchema.MimeContent))

    I can bind to the email and save attachments/subject/body etc but when trying to use the MIMEContent to save the email, I get the exception.Online searching shows it may be due to the DST settings on the server, but all DST updates have been installed on the server, and the email is a new one I create each time for testing.

    The date in question is: "Unable to convert 2009-01-01T00:00:00.000 from (UTC+08:00) Perth to UTC.

    The exception detail is:

    Microsoft.Exchange.WebServices.Data.TimeZoneConversionException was unhandled by user code
      HResult=-2146233088
      Message=Unable to convert 2009-01-01T00:00:00.000 from (UTC+08:00) Perth to UTC.
      Source=Microsoft.Exchange.WebServices
      StackTrace:
           at Microsoft.Exchange.WebServices.Data.EwsUtilities.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
           at Microsoft.Exchange.WebServices.Data.ExchangeServiceBase.ConvertDateTimeToUniversalDateTimeString(DateTime value)
           at Microsoft.Exchange.WebServices.Data.EwsServiceXmlWriter.TryConvertObjectToString(Object value, String& strValue)
           at Microsoft.Exchange.WebServices.Data.EwsServiceXmlWriter.WriteElementValue(XmlNamespace xmlNamespace, String localName, String displayName, Object value)
           at Microsoft.Exchange.WebServices.Data.EwsServiceXmlWriter.WriteElementValue(XmlNamespace xmlNamespace, String localName, Object value)
           at Microsoft.Exchange.WebServices.Data.AbsoluteDateTransition.WriteElementsToXml(EwsServiceXmlWriter writer)
           at Microsoft.Exchange.WebServices.Data.ComplexProperty.WriteToXml(EwsServiceXmlWriter writer, XmlNamespace xmlNamespace, String xmlElementName)
           at Microsoft.Exchange.WebServices.Data.ComplexProperty.WriteToXml(EwsServiceXmlWriter writer, String xmlElementName)
           at Microsoft.Exchange.WebServices.Data.TimeZoneTransition.WriteToXml(EwsServiceXmlWriter writer)
           at Microsoft.Exchange.WebServices.Data.TimeZoneDefinition.WriteElementsToXml(EwsServiceXmlWriter writer)
           at Microsoft.Exchange.WebServices.Data.ComplexProperty.WriteToXml(EwsServiceXmlWriter writer, XmlNamespace xmlNamespace, String xmlElementName)
           at Microsoft.Exchange.WebServices.Data.ComplexProperty.WriteToXml(EwsServiceXmlWriter writer, String xmlElementName)
           at Microsoft.Exchange.WebServices.Data.TimeZoneDefinition.WriteToXml(EwsServiceXmlWriter writer)
           at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.WriteToXml(EwsServiceXmlWriter writer)
           at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.TraceAndEmitRequest(IEwsHttpWebRequest request, Boolean needSignature, Boolean needTrace)
           at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.BuildEwsHttpWebRequest()
           at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request)
           at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()
           at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
           at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalLoadPropertiesForItems(IEnumerable`1 items, PropertySet propertySet, ServiceErrorHandling errorHandling)
           at Microsoft.Exchange.WebServices.Data.Item.InternalLoad(PropertySet propertySet)
           at Microsoft.Exchange.WebServices.Data.ServiceObject.Load(PropertySet propertySet)
           at EWSTest.Notifications.OnEvent(Object sender, NotificationEventArgs args) in C:\Users\ABhudia\Ash\TFS\VS2010\Exchange Web Service\PoC With Attachment\EWSTest\EWSTest_Console.cs:line 109
           at Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection.IssueNotificationEvents(GetStreamingEventsResponse gseResponse)
           at Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection.HandleServiceResponseObject(Object response)
           at Microsoft.Exchange.WebServices.Data.HangingServiceRequestBase.ParseResponses(Object state)
      InnerException: System.ArgumentException
           HResult=-2147024809
           Message=The supplied DateTime represents an invalid time.  For example, when the clock is adjusted forward, any time in the period that is skipped is invalid.
    Parameter name: dateTime
           Source=mscorlib
           ParamName=dateTime
           StackTrace:
                at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData)
                at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
                at Microsoft.Exchange.WebServices.Data.EwsUtilities.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
           InnerException:

    I don't know where this date value is coming from - any suggestions?

    Thursday, April 18, 2013 5:16 AM

All replies

  • Try using a different timezone id

    e.g.

    TimeZoneInfo.FindSystemTimeZoneById("Singapore Standard Time")
    Tuesday, July 30, 2013 7:15 AM
  • Hi, I fixed this problem setting the timezone for the ExschangeService to GMT. Like this:

    Me.m_Exchange = NewExchangeService(version, TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"))

    Regrads,

    MarianoC.

    Wednesday, August 7, 2013 5:06 PM
  • Yep, I used KL / Malaysia. Don't use GMT as your input times need to be GMT +8 hours.

    This has been broken since WA had Daylight savings, and then rolled it back. MS patched the change but this stuff is still broken.


    edit broken in EWS 1.2, 2.0 and 2.2 (current, it seems)
    • Edited by Neil_McIntyre Friday, May 8, 2015 12:47 PM additional info
    Friday, May 8, 2015 12:46 PM