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

NullReferenceException in ExecutePost when Header value is null #2227

Closed
TimSirmovics opened this issue Jun 18, 2024 · 0 comments · Fixed by #2241
Closed

NullReferenceException in ExecutePost when Header value is null #2227

TimSirmovics opened this issue Jun 18, 2024 · 0 comments · Fixed by #2241
Labels

Comments

@TimSirmovics
Copy link
Contributor

Describe the bug
When adding a header with a null value, an exception is thrown when sending the request and requires looking at the call stack to infer the cause of the exception.
I think this could be made clearer by throwing the exception when adding the header, or returning a more detailed message in the later thrown exception.

To Reproduce

var client = new RestClient("baseUrl");

var request = new RestRequest("endpoint");
request.AddJsonBody(model);
request.AddHeader("X-SomeHeader", null);

var response = client.ExecutePost(request);

Expected behavior
Either an exception is thrown on the AddHeader() call, or a more detailed exception message is returned when calling ExecutePost()

Stack trace

RestSharp.HttpRequestMessageExtensions.AddHeaders.__AddHeader|0_2(RestSharp.Parameter, System.Net.Http.Headers.HttpHeaders)
RestSharp.HttpRequestMessageExtensions.AddHeaders.AnonymousMethod__1(RestSharp.Parameter)
RestSharp.HttpRequestMessageExtensions.AddHeaders(System.Net.Http.HttpRequestMessage, RestSharp.RequestHeaders)
RestSharp.RestClient.ExecuteRequestAsync(RestSharp.RestRequest, System.Threading.CancellationToken)
RestSharp.RestClient.ExecuteAsync(RestSharp.RestRequest, System.Threading.CancellationToken)
RestSharp.AsyncHelpers.CustomSynchronizationContext.Run.__PostCallback|7_0(object)
RestSharp.AsyncHelpers.CustomSynchronizationContext.Run()
RestSharp.AsyncHelpers.RunSync(System.Func<System.Threading.Tasks.Task>)
RestSharp.AsyncHelpers.RunSync(System.Func<System.Threading.Tasks.Task>)
RestSharp.RestClientExtensions.ExecutePost(RestSharp.IRestClient, RestSharp.RestRequest)

Desktop (please complete the following information):

  • OS: Windows 11
  • .NET version: .NET 8.0
  • Version 111.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant