OData / OData/AspNetCoreOData

JsonSerializationException when using $select OData queries on .Net 6

Open
#774 17 comments 3 reactions 1 assignee View on GitHub

@xuzhg is already working on this.

Since Jan 18, 2023.

bug
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):

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:
image
Error Message:
image

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.