You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When configuring a RestClient and using that client to execute multiple threaded executes, this works most of the time, but sometimes gives following exception:
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at RestSharp.RestClient.ConfigureHttp(IRestRequest request, IHttp http)
at RestSharp.RestClient.ExecuteAsync(IRestRequest request, Action`2 callback, String httpMethod, Func`4 getWebRequest)
at RestSharp.RestClient.ExecuteAsync(IRestRequest request, Action`2 callback)
at RestSharp.RestClient.ExecuteAsync[T](IRestRequest request, Action`2 callback)
at RestSharp.RestClientExtensions.ExecuteAsync[T](IRestClient client, IRestRequest request, Action`1 callback)
// move RestClient.DefaultParameters into Request.Parameters
foreach(var p in DefaultParameters)
{
if(request.Parameters.Any(p2 => p2.Name == p.Name && p2.Type == p.Type))
{
continue;
}
request.AddParameter(p);
}
enumerates over the collection which could be changed while enumerating because an execute on another thread adds a parameter to the default parameter collection of the restclient.
I think that adding the accept headers in each request is not necessary. On the contrary, for each new request a parameter is added to the collection and this makes the collection constantly grow.
I would suggest moving the adding of the accept header out of the Execute method, although I don't immediately see another method where this would fit.
The text was updated successfully, but these errors were encountered:
nickvane
pushed a commit
to nickvane/RestSharp
that referenced
this issue
Apr 9, 2013
Since anyone can directly reference DefaultParameters, it's possible for
a null value to be added. Definitely a programming mistake most likely,
but we seem to have run into this somehow. It might have been due to
weird multi-threading issues like those in restsharp#368 so I'm not sure if this
is still a problem. I figured it doesn't hurt to have defense in depth.
:)
When configuring a RestClient and using that client to execute multiple threaded executes, this works most of the time, but sometimes gives following exception:
This happens because the defaultparameter collection is changed on each execute.
https://github.com/restsharp/RestSharp/blob/master/RestSharp/RestClient.Async.cs line 78
The ConfigureHttp method in https://github.com/restsharp/RestSharp/blob/master/RestSharp/RestClient.cs line 286
enumerates over the collection which could be changed while enumerating because an execute on another thread adds a parameter to the default parameter collection of the restclient.
I think that adding the accept headers in each request is not necessary. On the contrary, for each new request a parameter is added to the collection and this makes the collection constantly grow.
I would suggest moving the adding of the accept header out of the Execute method, although I don't immediately see another method where this would fit.
The text was updated successfully, but these errors were encountered: