C
C#3mo ago
Demonik

RestSharp multipart request in from Unity fails with NRE after successfully sending request

With this 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)
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)
This is what I'm doing:
request.Method = Method.Post;
request.AddFile("file1", file.FullName);
request.AddParameter("payload_json", message.ToJsonString(), ParameterType.RequestBody);
var response = await client.ExecuteAsync(request);
request.Method = Method.Post;
request.AddFile("file1", file.FullName);
request.AddParameter("payload_json", message.ToJsonString(), ParameterType.RequestBody);
var response = await client.ExecuteAsync(request);
It actually successfully sends request but immediately throws exception inside. Without attachment it works fine. Am I doing something wrong or is this a bug?
1 Reply
Demonik
Demonik3mo ago
Exactly same request but without multipart works RestSharp 110.2.0 I'll just post since I figured out what issue was - it's with the System.Net.Http bundled with unity, it has a bug where double dispose on MultipartContent causes NRE because it sets internal list to null in dispose and doesn't check for null before enumerating; this issue isn't present in the reference .NET code and I found it in Unity one by debugging with dnspy the only way to avoid issue it to directly use HttpClient for multipart requests and avoid doing double dispose (it disposes request itself on send) this is a bug with assembly bundled with Unity because double dispose is supposed to be safe to do
Want results from more Discord servers?
Add your server
More Posts
When I set PublishAot to true, I get "Publish has encountered an error.When I set PublishAot to true, I get "Publish has encountered an error. We were unable to determine Blurring an Image in C#, working slowlySmall glitch but my algorithm for making this image blur is running super slow, going from the top oMy socket won't send data to 600 endpointsMy application sends a packet to 600 servers in order to gather data about active players and such. Help with Azure Cognitive Services?Currently I would like to add AI to my personal projects, I read about Azure cognitive services, I w✅ Need some help debugging EF Core db queryI am trying to get some information from the database. I am running this query: ```CS var ordersInLa✅ Seed cannot be added because of required property IDThe seed entity for entity type 'Series' cannot be added because no value was provided for the requiRazor Page Validation Error MessageFor "int" and "decimal" it gives a standard error message instead of my pre defined. "Is not valid fHelp Needed: Choosing Between VSCode on Mac or Visual Studio via Remote Desktop for Windows BackgrouI'm starting a new project and can't decide between two options: using VSCode on my Mac or using Vis✅ "Animate" an image along a axisHi, i'm using wpf and i want to code the "animation" of an Image. I want to move the image on an axi2D array doesn't initialize the correct size (Checked with breakpoints)In the ConsoleGraphic ctor I initialize a new 2D Glyph array. When the _console.Buffer.Width is 960