I am working on a Xamarin cross platform project that talks to a web service. The general form of my service calls follows the following pattern:
var clientQuery = new MyClientsQuery(param1, param2);
var json = JsonConvert.SerializeObject(clientQuery);
var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpClient _httpClient = new HttpClient();
response = await _httpClient.PostAsync(ServiceURL, content);
if (response.IsSuccessStatusCode)
{
json = await response.Content.ReadAsStringAsync();
}
This usually works fine, but after making a few calls during the execution of the app, PostAsync generates the exception:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I suspect that I am running into some sort of connection limit, but I can not find any documentation in System.Net.Http that indicates when I should be disposing of objects or any other clue.
Why is this happening?