JsonSerializationException when using $select OData queries on .Net 6
@xuzhg is already working on this.
Since Jan 18, 2023.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Assemblies affected
8.0.12
Describe the bug
When using $select or the $expand query statements with OData to query a cosmosDB collection I receive the following exceptions:
"Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'DeclaringType' with type 'Microsoft.OData.Edm.EdmEntityType'. Path 'TypedProperty.SchemaElements[0].DeclaredKey[0]'."
My use case is similar to the one described in this issue (now closed with no resolution):
- https://github.com/OData/AspNetCoreOData/issues/503
- I attempted to add ".AddODataNewtonsoftJson()" to my services to fix the issue but this only works when I return a local collection. If I attempt to query cosmosDB I hit the same problem (https://github.com/JamesNK/Newtonsoft.Json/issues/2649)
Reproduce steps
I've attached my test code (minus crednetials) in the post.
Data Model
Please share your Data model, for example, your C# class.
EDM (CSDL) Model
Please share your Edm model, for example, CSDL file.
You can send $metadata to get a CSDL XML content.
Request/Response
Please share your request Uri, head or the request body
Please share your response head, body.
Expected behavior
Be able to run a query with a select statment.
CosmosTest.zip
Screenshots
Query I am attempting to run:

Error Message:

Additional context
I can see that the ".AddODataNewtonsoftJson()" method has an overload that takes parameters and that perhaps I could configure the ReferenceLoopHandling there to ignore this issue, but I can't find an example of how to use this anywhere. I've tried to add this setting in a couple of different places but didn't succeed.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.