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
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<edmx:Edmxxmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"Version="4.0">
<edmx:DataServices>
<Schemaxmlns="http://docs.oasis-open.org/odata/ns/edm"Namespace="SampleNs.Models">
<EntityTypeName="Customer">
<Key>
<PropertyRefName="Id"/>
</Key>
<PropertyName="Id"Type="Edm.Int32"Nullable="false"/>
<PropertyName="Name"Type="Edm.String"Nullable="false"/>
<PropertyName="StreetAddress"Type="SampleNs.Models.Address"Nullable="false"/>
</EntityType>
<ComplexTypeName="Address">
<PropertyName="City"Type="Edm.String"Nullable="false"/>
</ComplexType>
</Schema>
<Schemaxmlns="http://docs.oasis-open.org/odata/ns/edm"Namespace="Default">
<EntityContainerName="Container">
<EntitySetName="Customers"EntityType="SampleNs.Models.Customer"/>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
So what will happen is that since Type will be null, the logic in ResourceContext.GetPropertyValue breaks and an exception is thrown that the property couldn't be found on the type, even when the property exists.
Changing the line I referenced as follows fixes the issue.
This works because we're able to later evaluate that it's a DeltaOfT object.
We need to determine if this is the best way to fix the issue. There could be room for further improvement. We call deltaNestedProperties.TryGetValue method to retrieve the value for the nested resource here:
When then call obj.GetType() to get the type of the value, that type we later pass onto WriteDeltaComplexAndExpandedNavigationPropertyAsync, where we later make a second call to retrieve the nested resource value at this point:
The property value that is returned would give us the same type that was passed into the method...
It's not clear why only the navigation property type is passed, and why this was not expanded to {nested resource type} so it covers both complex and navigation properties.
The text was updated successfully, but these errors were encountered:
Assemblies affected
Describe the bug
When a typed delta response payload contains a nested
Delta<{Complex Type}>
, a serialization exception is thrownReproduce steps
Consider a simple OData service that processes a delta payload comprising of the following:
Data model:
Service Configuration:
EDM (CSDL) Model
Request/Response
Uri:
Body:
Exception:
Expected behavior
Expected response to be returned:
Screenshots
Deserialization is successful:
Additional context
The issue is related to this line here:
AspNetCoreOData/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataResourceSerializer.cs
Line 206 in c60d9e0
navigationPropertyType
is passed into the function and it has a default value ofnull
.For single-valued delta complex properties, it's not passed
ODataSerializerContext.Type
is used byIsDeltaOf
property to check if we're dealing with a delta at this point:AspNetCoreOData/src/Microsoft.AspNetCore.OData/Formatter/ResourceContext.cs
Line 163 in c60d9e0
So what will happen is that since
Type
will be null, the logic inResourceContext.GetPropertyValue
breaks and an exception is thrown that the property couldn't be found on the type, even when the property exists.Changing the line I referenced as follows fixes the issue.
This works because we're able to later evaluate that it's a
DeltaOfT
object.We need to determine if this is the best way to fix the issue. There could be room for further improvement. We call
deltaNestedProperties.TryGetValue
method to retrieve the value for the nested resource here:AspNetCoreOData/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataResourceSerializer.cs
Line 304 in c60d9e0
When then call
obj.GetType()
to get the type of the value, that type we later pass ontoWriteDeltaComplexAndExpandedNavigationPropertyAsync
, where we later make a second call to retrieve the nested resource value at this point:AspNetCoreOData/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataResourceSerializer.cs
Line 179 in c60d9e0
The property value that is returned would give us the same type that was passed into the method...
It's not clear why only the navigation property type is passed, and why this was not expanded to
{nested resource type}
so it covers both complex and navigation properties.The text was updated successfully, but these errors were encountered: