AvaloniaUI/Avalonia · error · ExpressionParseException

Unexpected token

Error message

Unexpected token

What it means

Error "Unexpected token" thrown in AvaloniaUI/Avalonia.

Source

Thrown at src/Avalonia.Base/Rendering/Composition/Expressions/ExpressionParser.cs:232

                }
                
                ExpressionType? op = null;
                if (left.NotEmpty)
                {
                    if (parser.TryConsume('?'))
                    {
                        var truePart = ParseTillTerminator(ref parser, ":",
                            false, true, out _);
                        // pass through the current parsing rules to consume the rest
                        var falsePart = ParseTillTerminator(ref parser, terminatorChars, throwOnTerminator, throwOnEnd,
                            out token);
                        
                        return new ConditionalExpression(left.ToExpression(), truePart, falsePart);
                    }
                    
                    // We expect a binary operator here
                    if (!TryParseOperator(ref parser, out var sop))
                        throw new ExpressionParseException("Unexpected token", parser.Position);
                    op = sop;
                }
                
                // We expect an expression to be parsed (either due to expecting a binary operator or parsing the first part
                var applyNegation = false;
                while (parser.TryConsume('!')) 
                    applyNegation = !applyNegation;

                var applyUnaryMinus = false;
                while (parser.TryConsume('-')) 
                    applyUnaryMinus = !applyUnaryMinus;

                Expression? parsed;
                
                if (parser.TryConsume('(')) 
                    parsed = ParseTillTerminator(ref parser, ")", false, true, out _);
                else if (parser.TryParseCall(out var functionName))
                {

View on GitHub (pinned to 11c5427268)

Solutions

  1. Review the expression grammar and replace the unexpected token with a valid operand, operator, or function name.
  2. Simplify the expression and reintroduce parts incrementally to locate the invalid token.

When it happens

Trigger: Raised when the expression parser reads a token it cannot handle while building the expression tree. Defend by restricting expressions to the supported grammar and validating user-supplied expression text ahead of parsing.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/81fc2821de5009bf. Report an issue: GitHub.