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:204

                if (_expressions == null)
                    return _first ?? throw new InvalidOperationException();
                return ToExpression(0, _expressions.Count - 1);
            }
        }

        static Expression ParseTillTerminator(ref TokenParser parser, string terminatorChars, 
            bool throwOnTerminator,
            bool throwOnEnd,
            out char? token)
        {
            ExpressionOperatorGroup left = default;
            token = null;
            while (true)
            {
                if (parser.TryConsumeAny(terminatorChars.AsSpan(), out var consumedToken))
                {
                    if (throwOnTerminator || left.Empty)
                        throw new ExpressionParseException($"Unexpected '{token}'", parser.Position - 1);
                    token = consumedToken;
                    return left.ToExpression();
                }
                parser.SkipWhitespace();
                if (parser.Length == 0)
                {
                    if (throwOnEnd || left.Empty)
                        throw new ExpressionParseException("Unexpected end of  expression", parser.Position);
                    return left.ToExpression();
                }
                
                ExpressionType? op = null;
                if (left.NotEmpty)
                {
                    if (parser.TryConsume('?'))
                    {
                        var truePart = ParseTillTerminator(ref parser, ":",
                            false, true, out _);

View on GitHub (pinned to 11c5427268)

Solutions

  1. Correct the expression string so the reported token is valid in that position; check for typos in property names, operators, or function calls.
  2. Quote string literals and ensure identifiers match existing animatable property names on the target visual.

When it happens

Trigger: Raised when the composition expression tokenizer encounters a token that is not valid at the current parse position. Defend by checking expression syntax (identifiers, operators, parentheses) before use and by guarding against malformed input strings.

Common situations: See trigger scenarios.


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