Repository navigation
Open
Description
Goodmorning,
I'm trying to call the Aggregate method but I don't get it to work. I keep getting the error that a property/field does not exisit on either the type I'm working with, or the type of the property itself like 'Int32'.
The code below renders an exception:
var models = new Model[]
{
new Model { Number = 1 },
new Model { Number = 10 },
new Model { Number = 14 }
};
var parameter = Expression.Parameter(typeof(Model[]), "models");
var parser = new ExpressionParser(
[parameter],
"models.Aggregate(0, (currentMax, next) => Math.Max(currentMax, next.Number))",
[],
new ParsingConfig());
// The expression below also produces an exception:
// "models.Select(x => x.Number).Aggregate((currentMax, next) => Math.Max(currentMax, next))"
// This expression gives an error that the field or property currentMax does not exist on 'Int32'
var expression = parser.Parse(typeof(int));
var labmda = Expression.Lambda<Func<Model[], int>>(expression, parameter);
var method = labmda.CompileFast();
var result = method(models);
Console.Write(result);The code above produces the following exception:
Unhandled exception. No property or field 'currentMax' exists in type 'Model' (at index 21)
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression, String id)
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIdentifier()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimaryStart()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArithmetic()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseParenExpression()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimaryStart()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArithmetic()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOutKeyword()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArguments()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArgumentList()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.TryParseEnumerable(Expression instance, Type enumerableType, String methodName, Type type, Expression[]& args, Expression& expression)
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression, String id)
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArithmetic()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
The Math.Max usage is just used for example here, I'm aware of the Min and Max methods of Linq.
Metadata
Metadata
Assignees
Labels
No labels
Activity
menes97 commentedon Nov 19, 2026
Reproduced on master (0297001, v1.8.0, net10.0). Both forms fail with
No property or field 'currentMax' exists in type 'Model'(and'Int32'for theSelect(...)version).Aggregateisn't implemented.TryParseEnumerableinExpressionParser(around lines 2253–2406) parses the arguments with a single implicititparameter of the element type. It doesn't support a two-parameter lambda(acc, next) => ..., socurrentMaxgets looked up as a member ofModel/Int32.For this particular case the dedicated aggregates work (verified on the same build):
models.Max(x => x.Number)models.Select(x => x.Number).Max()models.Sum(Number)