-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microsoft.OData.ODataException: Nested collection instances are not allowed #2499
Comments
Migrated client proxy version 3.0 to client proxy version 4.0 using https://www.nuget.org/packages/Microsoft.OData.Cli which is used for running the extended tests. The client proxy is up to date as the new proxy file is auto generated every time with the build. All the calls failing are scoped to one entity i.e. User. The entity is an open type. |
I tried to compare the tests failing vs successful, only difference was that this failure had some properties that were skipped in metadata and proxy file. Looks like this exception is thrown when we have dynamic properties with ODataCollection value? |
From the CSDL standard, the type of a collection property must be either a primitive, complex type, or enumeration type. Having a nested collections doesn't really make sense, the nested collection would need to be a property on a complex type. Can you please share your request body, and can you please share the CSDL that your client code is using? |
We use OData client proxy for running extended tests. Even if populate single property like displayName, all the other properties are sent in the request body. This was a problem for privileged properties because after a privileged property is included in the request body then our service used to throw an exception if the token didn't have access. So, the solution added was to skip adding the privileged properties on the metadata and proxy file so that a request body won't every contain a privileged property. This worked file for OData V3 proxy. But as we migrated to OData V4 properties and updated OData client library, we started seeing this issue. The privileged property like ExternalUserInformation having collection of complex type is written in the response (as it's part of Graph model) and because this does not exist on metadata/proxy, OData client lib populates this as dynamic properties. And I see that the nested collection of complex type on dynamic property is not supported.
In short, the request body does not contain this property. But on our service side, this property is written in the response (as the token gets access). I think because the metadata/proxy does not contain this property, this property becomes the dynamic property while OData client lib handles the response. And the collection of complex type on dynamic complex type property is throwing the exception. |
Seeing the below exception:
Assemblies affected
OData .Net lib 7.9.3
Looks like validation for ODataCollectionValue is throwing the exception:
Microsoft.OData.Client.DataServiceRequestException: An error occurred while processing this request. ---> Microsoft.OData.ODataException: Nested collection instances are not allowed.
STACK TRACE:
at Microsoft.OData.ValidationUtils.ValidateCollectionItem(Object item, Boolean isNullable)
at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadCollectionValue(IEdmCollectionTypeReference collectionValueTypeReference, String payloadTypeName, ODataTypeAnnotation typeAnnotation)
at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, PropertyAndAnnotationCollector propertyAndAnnotationCollector, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideResourceValue, String propertyName, Nullable
1 isDynamicProperty) at Microsoft.OData.ODataUriConversionUtils.ConvertFromResourceOrCollectionValue(String value, IEdmModel model, IEdmTypeReference typeReference) at Microsoft.OData.ODataUriUtils.ConvertFromUriLiteral(String value, ODataVersion version, IEdmModel model, IEdmTypeReference typeReference) at Microsoft.OData.Client.CommonUtil.ParseJsonToPrimitiveValue(String rawValue) at Microsoft.OData.Client.Materialization.StructuralValueMaterializationPolicy.MaterializeDynamicProperty(ODataProperty property, Object instance) at Microsoft.OData.Client.Materialization.EntryValueMaterializationPolicy.MaterializeResolvedEntry(MaterializerEntry entry, Boolean includeLinks) at Microsoft.OData.Client.Materialization.ODataEntityMaterializerInvoker.DirectMaterializePlan(Object materializer, Object entry, Type expectedEntryType) at Microsoft.OData.Client.Materialization.ODataEntityMaterializer.ReadImplementation() at Microsoft.OData.Client.MaterializeAtom.MoveNextInternal() at Microsoft.OData.Client.MaterializeAtom.MoveNext() at Microsoft.OData.Client.BaseSaveResult.MaterializeResponse(EntityDescriptor entityDescriptor, ResponseInfo responseInfo, String etag) at Microsoft.OData.Client.BaseSaveResult.HandleResponsePost(EntityDescriptor entityDescriptor, String etag) at Microsoft.OData.Client.BaseSaveResult.HandleResponsePost(Descriptor descriptor, HeaderCollection contentHeaders) at Microsoft.OData.Client.SaveResult.HandleResponse() --- End of inner exception stack trace --- at Microsoft.OData.Client.SaveResult.HandleResponse() at Microsoft.OData.Client.BaseSaveResult.EndRequest() at Microsoft.OData.Client.DataServiceContext.SaveChanges(SaveChangesOptions options) at Microsoft.Online.Test.DirectoryApi.ProvisioningEngine.RestProvisioningHandler.CreateObject[T](T restObjectValue, IDictionary
2& headers)Looking at this code https://github.com/OData/odata.net/blob/b37a90e32319636c368a2ce9e5ba2cf39cb65582/src/Microsoft.OData.Core/ValidationUtils.cs#L134 but not sure why OData Collection Value is not supported here. Could you please help us understand this and suggest what can we do to fix this?
The text was updated successfully, but these errors were encountered: