0
votes

I'm trying something new and got an old project working with EWS (Exchange WebService) and I'm trying to debug, as it's currently not working correctly. The error I get is this one:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.ArgumentException: An item with the same key has already been added. Key: Dlt/1916
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at Microsoft.Exchange.WebServices.Data.TimeZoneTransitionGroup.InitializeFromAdjustmentRule(AdjustmentRule adjustmentRule, TimeZonePeriod standardPeriod)
   at Microsoft.Exchange.WebServices.Data.TimeZoneDefinition..ctor(TimeZoneInfo timeZoneInfo)
   at Microsoft.Exchange.WebServices.Data.ExchangeServiceBase.get_TimeZoneDefinition()
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.WriteToXml(EwsServiceXmlWriter writer)
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.EmitRequest(IEwsHttpWebRequest request)
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.BuildEwsHttpWebRequest()
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request)
   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
   at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable`1 items, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode, ServiceErrorHandling errorHandling)
   at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode)
   at Microsoft.Exchange.WebServices.Data.Appointment.Save(FolderId destinationFolderId, SendInvitationsMode sendInvitationsMode)
   at SomeClassNameAndSomePath:TaskController.cs:line 246
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ExceptionContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
warn: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[2]
      The response has already started, the error page middleware will not be executed.
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:Error: An unhandled exception has occurred while executing the request.

I'm getting this when I'm trying to create a simple appointment within outlook 365. Code looks like this:

var mainCalendarItem = new Appointment(service) {
                    Subject = "test",
                    Body = "we have something here"
};
mainCalendarItem.Save(mainCalendar.Id, SendInvitationsMode.SendToNone);

All information seems to valid, the api seems to work, but I'm now working the second day on figuring out what's reason for this. Any help appreciated. Thanks in advance.

Some feedback about the calendar: It's empty. I'm using latest EWS library version: enter image description here

For a brief moment I thought I found the solution, but as soon as I set some TimeZoneInfo (timezone) different than UTC, the error returns.

As I already posted a solution, I deleted it again, that was the message:

https://social.msdn.microsoft.com/Forums/exchange/en-US/fff93bb4-bbb7-4646-a704-4131040ffe4b/ews-managed-api-argument-exception-on-reading-calendar-items?referrer=https://social.msdn.microsoft.com/Forums/exchange/en-US/fff93bb4-bbb7-4646-a704-4131040ffe4b/ews-managed-api-argument-exception-on-reading-calendar-items?forum=exchangesvrdevelopment

someone telling something about time zone was causing the problem for him, and also in my exception there is something about time zone, I've changed the initialization of the ExchangeService to one with timezone UTC:

var service = new ExchangeService(ExchangeVersion.Exchange2013_SP1, TimeZoneInfo.Utc)
1

1 Answers

0
votes

Having the exact same issue. The .Save works if I've instantiated the ExchangeService in UTC but then the appointment is in UTC instead of local. What solution did you arrive at?