none
EWS managed API: Argument Exception on reading calendar items. RRS feed

  • Question

  • Hi

    We have an application which reads the calendar items from the exchange for users. Most of the time it works fine, but one user faces this problem where he gets a "An item with the same key has already been added."  on reading the calendar folder.

    Here are the exception details

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

    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)

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

       at Microsoft.Exchange.WebServices.Data.TimeZoneDefinition.TryReadElementFromXml(EwsServiceXmlReader reader)

       at Microsoft.Exchange.WebServices.Data.ComplexProperty.LoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String xmlElementName)

       at Microsoft.Exchange.WebServices.Data.ComplexProperty.LoadFromXml(EwsServiceXmlReader reader, String xmlElementName)

       at Microsoft.Exchange.WebServices.Data.TimeZonePropertyDefinition.LoadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag)

       at Microsoft.Exchange.WebServices.Data.PropertyBag.LoadFromXml(EwsServiceXmlReader reader, Boolean clear, PropertySet requestedPropertySet, Boolean onlySummaryPropertiesRequested)

       at Microsoft.Exchange.WebServices.Data.FindItemResponse`1.InternalReadItemsFromXml(EwsServiceXmlReader reader, PropertySet propertySet, IList`1 destinationList)

       at Microsoft.Exchange.WebServices.Data.FindItemResponse`1.ReadElementsFromXml(EwsServiceXmlReader reader)

       at Microsoft.Exchange.WebServices.Data.ServiceResponse.LoadFromXml(EwsServiceXmlReader reader, String xmlElementName)

       at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.ParseResponse(EwsServiceXmlReader reader)

       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadResponse(EwsServiceXmlReader ewsXmlReader)

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

       at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()

       at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()

       at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems[TItem](IEnumerable`1 parentFolderIds, SearchFilter searchFilter, String queryString, ViewBase view, Grouping groupBy, ServiceErrorHandling errorHandlingMode)

       at Microsoft.Exchange.WebServices.Data.ExchangeService.FindAppointments(FolderId parentFolderId, CalendarView calendarView)

    Anyone has an idea what the problem is? 

    Thanks


    wpfnewbie

    Monday, August 6, 2012 4:28 PM

All replies

  • It sounds to me like you are trying to add another item with the same key as a previously added item.

    Since you show no code, we have no idea what you are using for the key, but in this user's case, it's not unique.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Monday, August 6, 2012 5:11 PM
  • I am just calling the ExchangeService.FindAppointments The stacktrace tells me that this is happening inside the EWS managed API code. Thanks Sumanth

    wpfnewbie

    Monday, August 6, 2012 5:31 PM
  • I'm fairly sure that's not your code.

    I'm going to have to refer you to Bill Stewart's excellent blog post "How to ask questions in a technical forum"

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Monday, August 6, 2012 5:58 PM
  • Here is the code i use

     var calenderFolder = CalendarFolder.Bind(this.service, WellKnownFolderName.Calendar);
    
                        // Set the properties which needs to be populated from the service.
                        var view = new CalendarView(fromDate, toDate);
                        view.PropertySet = new PropertySet();
                        view.PropertySet.Add(AppointmentSchema.StartTimeZone);
                        view.PropertySet.Add(AppointmentSchema.EndTimeZone);
                        view.PropertySet.Add(AppointmentSchema.Organizer);
                        view.PropertySet.Add(AppointmentSchema.Location);
                        view.PropertySet.Add(AppointmentSchema.Start);
                        view.PropertySet.Add(AppointmentSchema.End);
                        view.PropertySet.Add(AppointmentSchema.Subject);
                        view.PropertySet.Add(AppointmentSchema.Categories);
                        
                        FindItemsResults<Appointment> appointments = service.FindAppointments(WellKnownFolderName.Calendar, view);
    Thanks

    wpfnewbie

    Monday, August 6, 2012 8:18 PM
  • Are you using Visual Studio?

    If so, which line causes the exception when you step through the code?

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Monday, August 6, 2012 9:22 PM
  • This line

    FindItemsResults<Appointment> appointments = service.FindAppointments(WellKnownFolderName.Calendar, view);

    service is of type

    Microsoft.Exchange.WebServices.Data.ExchangeService

    Thanks


    wpfnewbie

    Monday, August 6, 2012 11:31 PM
  • Ok, We will get you there;

    We need a concise-but-complete code sample that reliably reproduces the
    problem, along with instructions for how to get the problem to occur. (Thanks to Peter Duniho)

    Please see Short but complete programs

    Without being able to compile and run your code, we will be of limited use in debugging it.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Tuesday, August 7, 2012 2:23 PM
  • Hi sumanthcs,

    If you read your exception you see it try to get value from TimeZone. So it should be the Start or EndTimeZone.
    Remove all your adds and only use the subject, try to add each time one extra till you get the exception again, so you know which property is the problem.

    I havent use this method never so cant give you an example. I have used the FindItems. Beyond an example:

    FindItemsResults<Item> items = _service.FindItems(WellKnownFolderName.Calendar, new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeCreated, DateTime.Today), new ItemView(100));

    I search between the CreateTime and Today for appointments.

    Thursday, August 9, 2012 8:12 AM
  • Thanks for the tip in my case it was the StartTimeZone that was causing the problem. Fortunately I didn't actual need it so I was able to remove it from the query.
    Friday, July 24, 2015 7:38 AM