Skip to content

Collection was modified; enumeration operation may not execute. #304

@1-Accelerator-1

Description

@1-Accelerator-1

internal static string GetCookiesFromCollectionAsString(Dictionary<string, string> cookieCollection)
{
if (cookieCollection == null || cookieCollection.Count == 0)
return string.Empty;
string cookieString = "";
if (cookieCollection != null)
{
foreach (var itm in cookieCollection)
{
cookieString += $"{itm.Key}={itm.Value};";
}
}
return cookieString;
}

My application uses multithreading and sometimes such an error occurs "Collection was modified; enumeration operation may not execute.", most likely since I use multithreading, then at the same time in the execution of this method, "cookieCollection" changes in another thread, which is why this error occurs.

StackTrace:
at System.Collections.Generic.Dictionary2.Enumerator.MoveNext() at Microsoft.PowerPlatform.Dataverse.Client.Utilities.GetCookiesFromCollectionAsString(Dictionary2 cookieCollection)
at Microsoft.PowerPlatform.Dataverse.Client.DataverseTelemetryBehaviors.BeforeSendRequest(Message& request, IClientChannel channel)
at System.ServiceModel.Dispatcher.ImmutableClientRuntime.BeforeSendRequest(ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.PrepareCall(ProxyOperationRuntime operation, Boolean oneway, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod, Object[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Reflection.DispatchProxyGenerator.Invoke(Object[] args)
at generatedProxy_1.Execute(OrganizationRequest )
at Microsoft.PowerPlatform.Dataverse.Client.Connector.WebProxyClientAsync1.ExecuteAction[TResult](Func1 action)
at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.Command_Execute(OrganizationRequest req, String errorStringCheck, Boolean bypassPluginExecution)

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvestigatingWe are looking into this issue at this time.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions