Closed
Description
Describe the bug
I'm trying to send request from Unity using RestSharp 110.2.0 - sending normal request works but when I make multipart request with attachment it sends requests and then immediately throws NullReferenceException from System.Net.Http.MultipartContent.Dispose
. I tried attaching file using stream creating callback and file name with same results. This is an attempt to send discord webhook request with attachment and message actually appears on the server despite NRE after sending.
To Reproduce
Sending request with this code succeeds but throws exception:
request.Method = Method.Post;
request.AddFile("file1", file.FullName);
request.AddParameter("payload_json", message.ToJsonString(), ParameterType.RequestBody);
// request.AddHeader("Content-Type", "multipart/form-data");
var response = await client.ExecuteAsync(request); // Throws from ExecuteAsync
Expected behavior
Function successfully returning response after request has been sent.
Stack trace
NullReferenceException: Object reference not set to an instance of an object
System.Net.Http.MultipartContent.Dispose (System.Boolean disposing) (at <92a43029e91441ee9df5714eb5dcd209>:0)
System.Net.Http.HttpContent.Dispose () (at <92a43029e91441ee9df5714eb5dcd209>:0)
RestSharp.RequestContent.Dispose () (at <dfd03b4ab8614e549933c37db1618c06>:0)
RestSharp.RestClient.ExecuteRequestAsync (RestSharp.RestRequest request, System.Threading.CancellationToken cancellationToken) (at <dfd03b4ab8614e549933c37db1618c06>:0)
RestSharp.RestClient.ExecuteAsync (RestSharp.RestRequest request, System.Threading.CancellationToken cancellationToken) (at <dfd03b4ab8614e549933c37db1618c06>:0)
TestComponent.TestWebhookSend () (at Assets/Runtime/Scripts/TestComponent.cs:106)
Desktop (please complete the following information):
- OS: Windows 10
- .NET version: Unity 2023.2.16f1 (I think .NET 6 internally / .NET Standard 2.1 level), both il2cpp AOT and mono runtimes
- Version 110.2.0