You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AddObjectStatic throws on any null property value (inconsistent with AddObject) #2400
RestRequest.AddObjectStatic(obj) throws when the object has any property whose value is null, instead of skipping that property. The reflection-based AddObject(obj) skips null properties, so the two APIs behave differently.
To Reproduce
usingRestSharp;publicclassPerson{publicstringName{get;set;}publicintAge{get;set;}}// Name is left nullvarrequest=newRestRequest("resource").AddObjectStatic(newPerson{Age=30});
Building the request throws immediately (before any HTTP call is made).
Expected behavior
null properties are skipped and the request is built from the non-null ones only. The snippet above should produce a single Age=30 parameter and not throw.
Stack trace
System.NullReferenceException: Object reference not set to an instance of an object.
at RestSharp.PropertyCache`1.Populator.GetStringValue(IConvertible convertible) in RestSharp/Request/PropertyCache.Populator.cs:line 385
at RestSharp.PropertyCache`1.Populator.Populate(IConvertible convertible, RequestProperty requestProperty, ICollection`1 parameters) in RestSharp/Request/PropertyCache.Populator.cs:line 202
at RestSharp.PropertyCache`1.Populator.<>c__DisplayClass8_0.<GetPopulate>b__0(T model, ICollection`1 parameters) in RestSharp/Request/PropertyCache.Populator.cs:line 84
at RestSharp.PropertyCache`1.Populator.Populate(T entity, ICollection`1 parameters) in RestSharp/Request/PropertyCache.Populator.cs:line 47
at RestSharp.PropertyCache`1.GetParameters(T entity, IEnumerable`1 populators) in RestSharp/Request/PropertyCache.cs:line 70
at RestSharp.PropertyCache`1.GetParameters(T entity) in RestSharp/Request/PropertyCache.cs:line 61
at RestSharp.RestRequestExtensions.AddObjectStatic[T](RestRequest request, T obj) in RestSharp/Request/RestRequestExtensions.Object.cs:line 63
Desktop:
OS: Windows 11
.NET version: .NET 8; affects all target frameworks
Activity
Fix #2400: AddObjectStatic throwing on null property values (#2401)