none
ArgumentException on async Folder.Bind RRS feed

  • Question

  • hi,

    we use EWS Managed API to Sync our CRM with the Exchange-Server. As long as I used EWS Mangage API 1.1 everything worked perfect. Now I updated to Api 2.0 (Dll-version: 15.0.516.14) and I'm getting an ArgumentException if I bind to the same Folder from diffrent threads and don't understand why.

    Here's a samplecode which raises the exception:

    private void TestAsyncFolderGet() { try { ExchangeService service = this.GetService(); Parallel.For(0, 20, (i) => { Folder fo = Folder.Bind(service, WellKnownFolderName.Inbox); });

    } catch (Exception ex) { this.State = "Failed: " + ex.Message; } } private ExchangeService GetService() { ExchangeService result = new ExchangeService(ExchangeVersion.Exchange2010); result.AutodiscoverUrl("test@foo.com"); return result; }

    My real scenario is that im getting changed items using a pullsubscription and handle the changes async. While doing this I'm binding to the parentfolder to get some informations.

    Can anyone help me avoid the Exception?

    Here's a  StackTrace of the raised Exception:

     System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.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(IEwsHttpWebResponse response)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalFindFolders(IEnumerable`1 parentFolderIds, SearchFilter searchFilter, FolderView view, ServiceErrorHandling errorHandlingMode)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.FindFolders(FolderId parentFolderId, FolderView view)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.<>c__DisplayClassa.<FindFolders>b__8()
       at BR.Framework.Exchange.Adapter.Handler.SafeExecutor.Execute[T](Func`1 action, ExchangeService service, ExchangeAdapter adapter, ExchangeIdentity user, Boolean suppresserror, List`1 errorstoignore, ServiceError& error)
       at BR.Framework.Exchange.Adapter.Handler.SafeExecutor.Execute[T](Func`1 action, ExchangeService service, ExchangeAdapter adapter, ExchangeIdentity user, Boolean suppresserror, List`1 errorstoignore)
       at BR.Framework.Exchange.Adapter.Handler.SafeExecutor.Execute[T](Func`1 action, ExchangeService service, ExchangeAdapter adapter, ExchangeIdentity user, Boolean suppresserror)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.FindFolders(FolderId id, Int32 offset, SearchFilter filter)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.FindFolders(FolderId id, Int32 offset)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.FindFolders(FolderId parentfolderid)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.GetSubFolders(FolderId parentfolderid, Boolean recursive)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.<>c__DisplayClass6.<GetSubFolders>b__3(Folder item)
       at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c()
       at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
       at System.Threading.Tasks.Task.<>c__DisplayClass7.<ExecuteSelfReplicating>b__6(Object )
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
       at System.Threading.Tasks.Task.Wait()
       at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
       at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
       at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.GetSubFolders(FolderId parentfolderid, Boolean recursive)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.<>c__DisplayClass6.<GetSubFolders>b__3(Folder item)
       at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c()
       at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
       at System.Threading.Tasks.Task.<>c__DisplayClass7.<ExecuteSelfReplicating>b__6(Object )
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
       at System.Threading.Tasks.Task.Wait()
       at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
       at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
       at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.GetSubFolders(FolderId parentfolderid, Boolean recursive)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.GetAllUserFolders()
       at BR.Framework.Exchange.Adapter.ExchangeAdapter.GetMailboxInfo(ExchangeIdentity user)
       at BR.SMARTCRM.Activities.Exchange.ConfigureAdapterForUserActivity.CheckMailboxLimits(LfdNr verlfdnr, ExchangeIdentity identity, Identity identitysetting)
       at BR.SMARTCRM.Activities.Exchange.ConfigureAdapterForUserActivity.Execute(CodeActivityContext context)
       at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
       at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
    ---> (Inner Exception #0) System.AggregateException: One or more errors occurred. ---> System.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(IEwsHttpWebResponse response)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalFindFolders(IEnumerable`1 parentFolderIds, SearchFilter searchFilter, FolderView view, ServiceErrorHandling errorHandlingMode)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.FindFolders(FolderId parentFolderId, FolderView view)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.<>c__DisplayClassa.<FindFolders>b__8()
       at BR.Framework.Exchange.Adapter.Handler.SafeExecutor.Execute[T](Func`1 action, ExchangeService service, ExchangeAdapter adapter, ExchangeIdentity user, Boolean suppresserror, List`1 errorstoignore, ServiceError& error)
       at BR.Framework.Exchange.Adapter.Handler.SafeExecutor.Execute[T](Func`1 action, ExchangeService service, ExchangeAdapter adapter, ExchangeIdentity user, Boolean suppresserror, List`1 errorstoignore)
       at BR.Framework.Exchange.Adapter.Handler.SafeExecutor.Execute[T](Func`1 action, ExchangeService service, ExchangeAdapter adapter, ExchangeIdentity user, Boolean suppresserror)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.FindFolders(FolderId id, Int32 offset, SearchFilter filter)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.FindFolders(FolderId id, Int32 offset)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.FindFolders(FolderId parentfolderid)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.GetSubFolders(FolderId parentfolderid, Boolean recursive)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.<>c__DisplayClass6.<GetSubFolders>b__3(Folder item)
       at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c()
       at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
       at System.Threading.Tasks.Task.<>c__DisplayClass7.<ExecuteSelfReplicating>b__6(Object )
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
       at System.Threading.Tasks.Task.Wait()
       at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
       at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
       at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.GetSubFolders(FolderId parentfolderid, Boolean recursive)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.<>c__DisplayClass6.<GetSubFolders>b__3(Folder item)
       at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c()
       at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
       at System.Threading.Tasks.Task.<>c__DisplayClass7.<ExecuteSelfReplicating>b__6(Object )
    ---> (Inner Exception #0) System.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(IEwsHttpWebResponse response)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalFindFolders(IEnumerable`1 parentFolderIds, SearchFilter searchFilter, FolderView view, ServiceErrorHandling errorHandlingMode)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.FindFolders(FolderId parentFolderId, FolderView view)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.<>c__DisplayClassa.<FindFolders>b__8()
       at BR.Framework.Exchange.Adapter.Handler.SafeExecutor.Execute[T](Func`1 action, ExchangeService service, ExchangeAdapter adapter, ExchangeIdentity user, Boolean suppresserror, List`1 errorstoignore, ServiceError& error)
       at BR.Framework.Exchange.Adapter.Handler.SafeExecutor.Execute[T](Func`1 action, ExchangeService service, ExchangeAdapter adapter, ExchangeIdentity user, Boolean suppresserror, List`1 errorstoignore)
       at BR.Framework.Exchange.Adapter.Handler.SafeExecutor.Execute[T](Func`1 action, ExchangeService service, ExchangeAdapter adapter, ExchangeIdentity user, Boolean suppresserror)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.FindFolders(FolderId id, Int32 offset, SearchFilter filter)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.FindFolders(FolderId id, Int32 offset)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.FindFolders(FolderId parentfolderid)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.GetSubFolders(FolderId parentfolderid, Boolean recursive)
       at BR.Framework.Exchange.Adapter.Helper.FolderHelper.<>c__DisplayClass6.<GetSubFolders>b__3(Folder item)
       at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c()
       at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
       at System.Threading.Tasks.Task.<>c__DisplayClass7.<ExecuteSelfReplicating>b__6(Object )<---
    <---

     
    Thursday, February 14, 2013 9:13 AM