Skip to content

NullReferenceException when applying custom aggregation over dynamic (open type) properties #1526

@NiazMohy-ud-din

Description

@NiazMohy-ud-din

Assemblies affected
Microsoft.AspNetCore.OData 9.3.0

Describe the bug
Custom aggregate function e.g. $apply=aggregate(... with custom.stdev) over dynamic properties (open type dictionary fields) throws NullReferenceException during parsing. The options ODataQueryOptions.Apply.ApplyClause contains the exception as soon as the action is called.

I can verify that the declared properties work fine, and I've successfully parsed custom.stdev using following query, where filesize is part of the entity:
$apply=aggregate(filesize with custom.stdev as filesizedev)

However, when the aggregated field is a dynamic (open type) property, the parser fails.
$apply=aggregate(dynprop with custom.stdev as dynpropdev)
Interesting is, if I add dynprop to EdmModel like following then the parsing of ApplyClause works:

var edmEntityType = (EdmEntityType) model.FindDeclaredType(typeof(MyEntity).FullName);
edmEntityType.AddStructuralProperty("dynprop", EdmPrimitiveTypeKind.Double);

Unfortunately, I can't do that, as the properties are dynamic and depend on the data.

Is there a supported way to dynamically provide type information for open-type properties at runtime, before the ODataQueryOptions is prepared for controller action?

If not, is there a recommended approach or extension point to safely support this scenario?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions