title: Updating custom header value added as DefaultRequestHeaders of HttpClient
body: <p>I have a static <strong>httpclient</strong> shared across requests and I want to add one custom header to it.</p>
  
  <pre><code>httpClient.DefaultRequestHeaders.Add("customHeader", somevalue.ToString());
  </code></pre>
  
  <p>But I noticed that on every request the value is getting added to that header which I intend to replace on each request. I try to remove the header if it is already exist and add again but it gives me an errors on <strong>load test</strong>.</p>
  
  <pre><code>if (httpClient.DefaultRequestHeaders.Contains("customHeader"))
          {
              httpClient.DefaultRequestHeaders.Remove("customHeader");
          }
  httpClient.DefaultRequestHeaders.Add("customHeader",somevalue.ToString());
  </code></pre>
  
  <p><strong>Errors</strong> -</p>
  
  <pre><code>System.ArgumentException: An item with the same key has already been added.
  System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
  System.ArgumentNullException: Value cannot be null.
  </code></pre>
  
  <p>How can I update the custom header value on each request?</p>