Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpClient.PostAsync disposes the HttpContent object in .NET Framework #3792

Open
bdcoder2 opened this issue Jan 22, 2020 · 2 comments
Open
Labels
area-System.Net Pri3 Indicates issues/PRs that are low priority untriaged New issue has not been triaged by the area owner

Comments

@bdcoder2
Copy link

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.

@dotnet-bot dotnet-bot added the untriaged New issue has not been triaged by the area owner label Jan 22, 2020
@carlossanlop
Copy link
Member

@scalablecory can you help triage this documentation issue?

@cremor
Copy link

cremor commented Jan 31, 2020

Note that this additional information would only be true for .NET Framework. For .NET Core it was changed to not dispose the content. See dotnet/corefx#19082

@PRMerger12 PRMerger12 added the Pri3 Indicates issues/PRs that are low priority label Nov 11, 2020
@gewarren gewarren changed the title https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.postasync?view=netframework-4.8#definition HttpClient.PostAsync disposed the HttpContent object in .NET Framework May 17, 2022
@gewarren gewarren changed the title HttpClient.PostAsync disposed the HttpContent object in .NET Framework HttpClient.PostAsync disposes the HttpContent object in .NET Framework May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Net Pri3 Indicates issues/PRs that are low priority untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

5 participants