我们在代码库中看到了以下堆栈跟踪:
System.ArgumentException: An item with the same key has already been added.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Net.Http.Headers.HttpHeaders.AddHeaderToStore(String name, HeaderStoreItemInfo info)
at System.Net.Http.Headers.HttpHeaders.SetParsedValue(String name, Object value)
at System.Net.Http.Headers.HttpContentHeaders.get_ContentLength()
at System.Net.Http.HttpClientHandler.PrepareAndStartContentUpload(RequestState state)
并将其缩小到我们调用的代码中的某个地方
HttpContent.ReadAsStringAsync()
发生这种情况时,我们可以确定 HttpContent 的实例正被多个线程使用,所有线程都以某种方式试图读取实际内容。尚未弄清楚内容的阅读如何影响标题。
如果可以执行 HttpContent 的深度克隆,假设所有内容负载已下载,我们将研究此选项。
任何人都遇到过这个问题,如果是这样,你是如何解决的?
提前致谢。