Getting following error while adding header to HTTP Client:
{"ClassName":"System.IndexOutOfRangeException","Message":"Index was outside the bounds of the array.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)\r\n at System.Net.Http.Headers.HttpHeaders.AddHeaderToStore(String name, HeaderStoreItemInfo info)\r\n at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
Following is the code how I am adding headers:
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("api_key", _apiKey);
client.DefaultRequestHeaders.Add("targetApp", "query");
client.DefaultRequestHeaders.Add("accept", "application/x-www-form-urlencoded");
client.DefaultRequestHeaders.Add("Application", _applicationName);
client.DefaultRequestHeaders.Add("TraceId", traceId.ToString());
This is an intermitter issue, to fix this we have to restart IIS, after this code work fine.
Thanks a lot for helping in advance
client
instance?traceId
in particular doesn't look much like a "default" header unless that client is tightly scoped. In other words: is thisclient
instance reused by anything concurrent?