RestSharp: NullReferenceException for body parameters that don't have a name
Expected Behavior
I would not have to add a name, or the error message would be clearer that a parameter name was missing.
Actual Behavior
A NullReferenceException is thrown.
Steps to Reproduce the Problem
- Add a request body parameter without a name
This must be the issue in RestClient.ConfigureHttp (it’s assuming the name is there):
var parameterExists =
request.Parameters.Any(p =>
p.Name.Equals(defaultParameter.Name, StringComparison.InvariantCultureIgnoreCase)
&& p.Type == defaultParameter.Type);
Specifications
- Version: 106.6.9.0
- Platform: .NET Framework
- Subsystem:
StackTrace
System.NullReferenceException: Object reference not set to an instance of an object.
at RestSharp.RestClient.<>c__DisplayClass172_0.<ConfigureHttp>b__8(Parameter p)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at RestSharp.RestClient.ConfigureHttp(IRestRequest request)
at RestSharp.RestClient.ExecuteAsync(IRestRequest request, Action`2 callback, String httpMethod, Func`4 getWebRequest)
at RestSharp.RestClient.ExecuteAsync(IRestRequest request, Action`2 callback, Method httpMethod)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 20 (10 by maintainers)
Commits related to this issue
- Explicit message in case of null parameter name. Fixes #1300 — committed to vbenedichuk/RestSharp by vbenedichuk 5 years ago
- Don't allow parameters without a name #1300 — committed to restsharp/RestSharp by alexeyzimarev 5 years ago
Yeah, the new version isn’t published yet. I made some more changes in preparation to move to better async handling and also to address some of the issues with exceptions handling
I updated the pull request to reflect your idea.
Seems like we are missing some tests. Indeed body parameters don’t need a name. I think a better fix would only check if the name is not empty for parameters that aren’t of type body.