HttpClient.PostAsync disposes the HttpContent object in .NET Framework #3792
Labels
area-System.Net
Pri3
Indicates issues/PRs that are low priority
untriaged
New issue has not been triaged by the area owner
On the following page:
https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.postasync?view=netframework-4.8#definition
Under the "Remarks" section, please include the following information:
The PostAsync method will automatically dispose the HttpContent object passed to it. If your use case requires retry requests, you will need to create a new HttpContent object before calling PostAsync.
The above tidbit of information is extremely useful when implementing code that implements "retry" attempts. Failure to adhere to the above recommendation will result in the following exception being raised:
Cannot access a disposed object. Object name: 'System.Net.Http.StringContent' exception.
Looking at the code for PostAsync, it appears the cancellation token is also disposed of -- might be useful to mention that in the remarks as well. I have not looked at other methods to see if this behavior is the same.
Thanks.
The text was updated successfully, but these errors were encountered: