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.
  • Loading branch information
alexeyzimarev committed May 22, 2024
1 parent 799c88a commit 2439bc5
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 2439bc5

Please sign in to comment.