-
Notifications
You must be signed in to change notification settings - Fork 474
Description
I am getting a 406 Not Acceptable
result when attempting to do perform SUM aggregation on a field in my model. After further investigation on debug, i see that the follow cast exception is being thrown on the NestedValue
property.
NestedValue = '(new System.Linq.SystemCore_EnumerableDebugView<System.Web.OData.Query.Expressions.NoGroupByAggregationWrapper>(result).Items[0]).Container.NestedValue' threw an exception of type 'System.InvalidCastException'
This seems to be preventing serialization from succeeding (see Additional Detail)
Assemblies affected
Microsoft.AspNet.OData 6.1.0
System.Web.OData 6.1.0.10907
Reproduce steps
I have the following setup, see the gist below. https://gist.github.com/gorillapower/35cf4258c0092c157bbd7ff27f9d93ef. It seems the fact that im using an IHTTPActionResult
response type and the ApplyTo
method is causing the serialization to fail. I get no errors when I use the [EnableQuery]
method and do not do an processing in my controller.
[EnableQuery]
[ODataRoute("events2")]
public IQueryable<EM_Event> GetEvents2()
{
return db2.EM_Events;
}
Expected result
{
"@odata.context": "https://localhost:44349/api/v2/$metadata#events2(Total)",
"value": [
{
"@odata.id": null,
"Total": 17050
}
]
}
Actual result
406 Not Acceptable HTTP Response
Additional detail
After further debugging, it looks like the inner cast exception above is causing the serialization to fail on the response. If I implement a custom JSON.Net
serializer i get the follow exception when trying to WriteToStreamAsync()
, Error getting value from 'NestedValue' on 'System.Web.OData.Query.Expressions.AggregationPropertyContainer+LastInChain'.
This looks similar to the issue #1078, however I still get this issue if i revert to Microsoft.AspNet.OData 6.0.0
fromMicrosoft.AspNet.OData 6.1.0
. In addition, I am using the JIL
JSON serializer as opposed to JSON.NET or any built in serializer, so I need to be able to handle this using any serializer.
Is it a case of handling this in my custom JSON serializer when this type is being passed?