Skip to content
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

Get the NestedValue on the LastInChain AggregationPropertyContainer goes wrong. #807

Closed
StefJanssen20 opened this issue Jan 13, 2023 · 4 comments

Comments

@StefJanssen20
Copy link

When executing this query:
{{HttpPrefix}}://{{CDLOperationaldata}}/WasteProducts?$apply=groupby((HomogeneousGroup/HomogeneousGroupId), aggregate($count as NumberOfWasteProducts))

I get the following error:
Newtonsoft.Json.JsonSerializationException: Error getting value from 'NestedValue' on 'Microsoft.AspNetCore.OData.Query.Container.AggregationPropertyContainer+LastInChain'.
---> System.InvalidCastException: Unable to cast object of type 'System.Guid' to type 'Microsoft.AspNetCore.OData.Query.Wrapper.GroupByWrapper'.
at lambda_method(Closure , Object )
at Newtonsoft.Json.Serialization.ExpressionValueProvider.GetValue(Object target)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Serialization.ExpressionValueProvider.GetValue(Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
at Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|21_0(ResourceInvoker invoker, IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Exceptionless.AspNetCore.ExceptionlessMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.OData.Routing.ODataRouteDebugMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Assemblies affected

  • Microsoft.AspNetCore.OData 8.0.12
  • Microsoft.AspNetCore.Mvc.NewtonsoftJson 3.1.32
  • AutoMapper.AspNetCore.OData.EFCore 4.0.0
  • Newtonsoft.Json 13.0.2

Describe the bug
On the property HomogeneousGroupId, he tries to get another NestedValue but since this is the lowest level (LastInChain), it will not be another GroupByWrapper but just de Type (Guid) of the HomogeneousGroupId.

Expected behavior
I expect that he just shows all de HomogeneousGroups with a count of all Wasteproducts that are in the HomogeneousGroup.

@StefJanssen20 StefJanssen20 added the bug Something isn't working label Jan 13, 2023
@ElizabethOkerio
Copy link
Contributor

@StefJanssen20 could you provide a repro of this issue.

@ElizabethOkerio ElizabethOkerio self-assigned this Jan 17, 2023
@ElizabethOkerio ElizabethOkerio added followup and removed bug Something isn't working labels Jan 17, 2023
@mikepizzo
Copy link
Member

The use of Automapper and Newtonsoft, along with EFCore and Aggregation, make it difficult to figure out what might be going on here. If you can provide a repro it would help us narrow down where the issue may be.

@xuzhg
Copy link
Member

xuzhg commented Jan 19, 2023

@StefJanssen20 If you are using Newtonsoft.JSON, please install 'https://www.nuget.org/packages/Microsoft.AspNetCore.OData.NewtonsoftJson'

Add call this method at 'https://github.com/OData/AspNetCoreOData/blob/main/sample/ODataNewtonsoftJsonSample/Startup.cs#L34' in the startup.

Let me know the result.

@xuzhg xuzhg self-assigned this Jan 19, 2023
@StefJanssen20
Copy link
Author

Thanks @xuzhg. This solved my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants