3

I am configuring a new OData project using this package. I have configured the project as per the documentation: https://aspnetboilerplate.com/Pages/Documents/OData-AspNetCore-Integration

When I access the route /odata/$metadata, I get the following exception:

Newtonsoft.Json.JsonSerializationException: 'Self referencing loop detected for property 'declaringType' with type 'Microsoft.OData.Edm.EdmEntityType'. Path 'result.schemaElements[0].declaredKey[0]'.'

This is thrown in the AbpUnitOfWorkMiddleware class when await _next(httpContext); is called.

I can bypass the issue by adding .AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); to the Startup class, but then this just keeps rendering the $metadata until the browser dies.

Could this be an issue with how the ABP framework handles this particular route? If I use the Microsoft.AspNetCore.OData without the ABP framework, then the $metadata route renders fine; it's actually returned as an XML document.

aaron
  • 39,695
  • 6
  • 46
  • 102
tjackadams
  • 815
  • 2
  • 9
  • 26

2 Answers2

2

Targeted solution

The solution is the same as the answer to Disable Wrapping of Controller Results.

One-liner quickfix

Alternatively, you can disable wrapping by default in the PreInitialize method of your module:

Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnSuccess = false;

Before:

After:

aaron
  • 39,695
  • 6
  • 46
  • 102
0

For me, it worked by adding AddODataNewtonsoftJson. you need to install a Nuget package Microsoft.AspNetCore.OData.NewtonsoftJson

services.AddControllers().AddNewtonsoftJson().AddODataNewtonsoftJson();
Kirti Chaturvedi
  • 1,245
  • 13
  • 24