GetUserAvailability exception :System.ArgumentException: An item with the same key has already been added. RRS feed

  • Question

  • try


                    results = this.exchangeService.GetUserAvailability(attendees, new TimeWindow(startTime, endTime), AvailabilityData.FreeBusy);           


                catch (Exception ex)


                    string attendeesString = string.Empty;

                    foreach (AttendeeInfo item in attendees)


                        attendeesString += item.SmtpAddress + "; ";



                    LogData logData = MethodLogUtilityForExchange.GetLogDataGetAttendeesAvailabilityDebug(attendeesString, startTime, endTime, ex);              

                    LogUtility.LogException(logData, "EWS GetAttendeesAvailability Exception", ex, LogCategory.MethodInformation);



    Exception stack trace :

    ExceptionSystem.ArgumentException: An item with the same key has already been added.

       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)

       at Microsoft.Exchange.WebServices.Data.ExchangeServiceBase.SaveHttpResponseHeaders(WebHeaderCollection headers)

       at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.ReadResponse(HttpWebResponse response)

       at Microsoft.Exchange.WebServices.Data.GetUserAvailabilityRequest.Execute()

       at Microsoft.Exchange.WebServices.Data.ExchangeService.GetUserAvailability(IEnumerable`1 attendees, TimeWindow timeWindow, AvailabilityData requestedData)

       at Intel.Exchange.WebServices.Extension.ExchangeServiceManager.GetAttendeesAvailability(List`1 attendees, DateTime startTime, DateTime endTime)

    Can you help in understanding the issue ? we are not handling any Dictionary explicitly here. but still we see the Dictionary key error. Not sure What would have gone wrong.

    • Edited by kp_89 Thursday, December 4, 2014 1:23 PM
    Thursday, December 4, 2014 1:21 PM

All replies

  • Hmm. Looking at the source for the EWS Managed API, it basically created a Dictionary object to save response headers. It appears that there is maybe a repeated header in the response, and when it tries to add the second one it gets that exception. You could add tracing to see what headers are coming back in the response to get a better idea of what's going on.
    Thursday, December 4, 2014 4:28 PM