Currently, if you call the Dynamics 365 Web API with a FetchXML aggregate query, the platform returns the following error: "An ODataPrimitiveValue was instantiated with a value of type 'Microsoft.Xrm.Sdk.AliasedValue'. ODataPrimitiveValue can only wrap values which can be represented as primitive EDM types."
The Web API should convert the AliasedValue to a primitive type to allow the calling application to get the value.
Microsoft has published documents that ask developers to use FetchXML aggregate queries instead of bringing back records and looping through them to get aggregate values, but the Web API itself does not support returning aggregate values. Please consider extending the platform to support this.