Skip to content

Commit

Permalink
Swallow disposal exception that might occur when disposing the conten…
Browse files Browse the repository at this point in the history
…t object. Fixes #2188. (#2201)
  • Loading branch information
alexeyzimarev authored May 26, 2024
1 parent fd392c9 commit 7334e28
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/RestSharp/Request/RequestContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace RestSharp;

class RequestContent(IRestClient client, RestRequest request) : IDisposable {
readonly List<Stream> _streams = new();
readonly List<Stream> _streams = [];
readonly ParametersCollection _parameters = new RequestParameters(request.Parameters.Union(client.DefaultParameters));

HttpContent? Content { get; set; }
Expand Down Expand Up @@ -222,6 +222,12 @@ void ReplaceHeader(string name, string? value) {

public void Dispose() {
_streams.ForEach(x => x.Dispose());
Content?.Dispose();

try {
Content?.Dispose();
}
catch (Exception e) when (e is ObjectDisposedException or NullReferenceException) {
// Already disposed
}
}
}

0 comments on commit 7334e28

Please sign in to comment.