EWS managed API: Argument Exception on reading calendar items.

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

August 6th, 2012 4:28pm

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

Free Windows Admin Tool Kit Click here and download it now
August 6th, 2012 5:11pm

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

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

Free Windows Admin Tool Kit Click here and download it now
August 6th, 2012 5:58pm

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
August 6th, 2012 8:18pm

Are you using Visual Studio?

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

Karl

Free Windows Admin Tool Kit Click here and download it now
August 6th, 2012 9:22pm

This line

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

service is of type

Microsoft.Exchange.WebServices.Data.ExchangeService

Thanks

August 6th, 2012 11:31pm

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

Free Windows Admin Tool Kit Click here and download it now
August 7th, 2012 2:23pm

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.

August 9th, 2012 8:12am

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.
Free Windows Admin Tool Kit Click here and download it now
July 24th, 2015 3:40am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics