Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
serialization exception when 2 subtypes define a property with the same name but different types #706
Exception when 2 types inherit from the same BaseType and use the same name for a property but with different property Types.
The example model and entity sets can be used. The entity sets Entity and E11021 fail with the error as in Actual Result, the other sets can be queried correctly. Doing a request without filters is all that is needed to let the exception occur.
The data of the entity sets.
Optional, details of the root cause if known. Delete this section if you have no additional details to add.
The WriteProperty method in the ODataJsonLightPropertySerializer invokes the JsonLightOutputContext.PropertyCacheHandler.GetProperty with the propertyName and owning type. In the GetProperty method only the propertyName and the currentResourceScope is taken into account to determine the uniqeName, which is used to check if the item is in the cache, which causes the problem.
I've created an own version which also takes the resource type full name into account, this fixes the problem.
Is it possible to include a similar fix?
I am able to reproduce the same exception with a different model and request. In our case we have a class, Release, with optional navigation properties to both a Family and a Snapshot:
<EntityType Name="Family"> <Key> <PropertyRef Name="Id" /> </Key> <Property Name="Id" Type="Edm.String" Nullable="false" /> </EntityType> <EntityType Name="Snapshot"> <Key> <PropertyRef Name="Id" /> </Key> <Property Name="Id" Type="Edm.Guid" Nullable="false" /> </EntityType> <EntityType Name="Release"> <Key> <PropertyRef Name="Id" /> </Key> <Property Name="Id" Type="Edm.String" Nullable="false" /> <NavigationProperty Name="Snapshot" Type="ODataSandbox.Models.Snapshot" /> <NavigationProperty Name="Family" Type="ODataSandbox.Models.Family" /> </EntityType> <EntitySet Name="Families" EntityType="ODataSandbox.Models.Family" /> <EntitySet Name="Snapshots" EntityType="ODataSandbox.Models.Snapshot" /> <EntitySet Name="Releases" EntityType="ODataSandbox.Models.Release"> <NavigationPropertyBinding Path="Snapshot" Target="Snapshots" /> <NavigationPropertyBinding Path="Family" Target="Families" /> </EntitySet>
I receive the exception when I issue a request to the Release endpoint and expand both navigation properties:
This prevents me, too, from upgrading to version 7.0.
I to am running into this issue. The example by tyrius02 is exactly what I'm running into except change out the types from Edm.String and Edm.Guid to Edm.Int32 and Edm.Int64
An incompatible primitive type 'Edm.Int32[Nullable=False]' was found for an item that was expected to be of type 'Edm.Int64[Nullable=True]'
If I change the name of my property it will work as expected. This breaks my API though as people are expecting Id
Note that this is only affected when the two objects are at the same level such as the example.
I also reproduced this issue.
added a commit
Feb 1, 2017
The PR (7f45fe6) from @robward-ms is the official fix; we need to spend some time looking through the PRs and issues that have built up from the 7.x release, but we will most likely release an official package later this month. Sorry I can't give you a more accurate estimate; depends on what we find that needs to be pulled in.