Case-Insensitive Property Matching NullRefs
After upgrading to 7.5.14 we observed a NullReferenceException in one of our test cases. After drilling in we found it was related to https://github.com/OData/WebApi/pull/2311 which swapped to allowing case-insensitive property matching during deserialization. We've worked around this by opting into the old behavior, but the nullref needs to be fixed.
Assemblies affected
Microsoft.AspNet.OData 7.5.14
Reproduce steps
- Send a POST request to update the value of
myPropertyon an open-type usingmypropertyas the name and have a null value
{
"myproperty": null
}
Expected result
Request should succeed
Actual result
Request fails
Additional detail
It looks like the property is found (i.e. it determines it's NOT dynamic), but it tries to treat a null value as a primitive which causes ConvertPrimitiveValue to fail:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Object.GetType()
at Microsoft.AspNet.OData.Formatter.EdmPrimitiveHelpers.ConvertPrimitiveValue(Object value, Type type)
at Microsoft.AspNet.OData.Formatter.Deserialization.DeserializationHelpers.SetDeclaredProperty(Object resource, EdmTypeKind propertyKind, String propertyName, Object propertyValue, IEdmProperty edmProperty, ODataDeserializerContext readContext)
at Microsoft.AspNet.OData.Formatter.Deserialization.DeserializationHelpers.ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, Object resource, ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
at Microsoft.AspNet.OData.Formatter.Deserialization.ODataResourceDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
at Microsoft.AspNet.OData.Formatter.Deserialization.ODataResourceDeserializer.ApplyResourceProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
at Microsoft.AspNet.OData.Formatter.Deserialization.ODataResourceDeserializer.ReadResource(ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
at Microsoft.AspNet.OData.Formatter.Deserialization.ODataResourceSetDeserializer.<ReadResourceSet>d__5.MoveNext()
It looks like there's a difference in the property.Value that's triggering the failure. In the case where you pass in myProperty oDataValue is null, while when you pass in myproperty oDataValue is not null:

This makes the kind be Primitive instead of None and it triggers ConvertPrimitiveValue.
@ificator Was the issue resolved by later versions of the library?