AvaloniaUI/Avalonia · error · ExpressionParseException

Member assignments not supported in binding expressions.

Error message

Member assignments not supported in binding expressions.

What it means

MemberAssignment is produced by MemberInitExpression, i.e. object-initializer syntax `new Foo { Bar = x.Baz }`. Object initialization is not a binding-path operation, so VisitMemberAssignment throws ExpressionParseException.

Source

Thrown at src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs:250

    protected override Expression VisitLabel(LabelExpression node)
    {
        throw new ExpressionParseException(0, $"Invalid expression type in binding expression: {node.NodeType}.");
    }

    protected override Expression VisitListInit(ListInitExpression node)
    {
        throw new ExpressionParseException(0, $"Invalid expression type in binding expression: {node.NodeType}.");
    }

    protected override Expression VisitLoop(LoopExpression node)
    {
        throw new ExpressionParseException(0, $"Invalid expression type in binding expression: {node.NodeType}.");
    }

    protected override MemberAssignment VisitMemberAssignment(MemberAssignment node)
    {
        throw new ExpressionParseException(0, "Member assignments not supported in binding expressions.");
    }

    protected override Expression VisitSwitch(SwitchExpression node)
    {
        throw new ExpressionParseException(0, $"Invalid expression type in binding expression: {node.NodeType}.");
    }

    protected override Expression VisitTry(TryExpression node)
    {
        throw new ExpressionParseException(0, $"Invalid expression type in binding expression: {node.NodeType}.");
    }

    protected override Expression VisitTypeBinary(TypeBinaryExpression node)
    {
        throw new ExpressionParseException(0, $"Invalid expression type in binding expression: {node.NodeType}.");
    }

    private Expression Add(Expression? instance, Expression expression, Action<CompiledBindingPathBuilder> build)

View on GitHub (pinned to 11c5427268)

Solutions

  1. Construct the object in the view-model and bind to that property.
  2. Use a converter that builds the object from the source value.
  3. Avoid object initializers in compiled-binding lambdas.

Example fix

// before
CompiledBinding.For(x => new VM { Text = x.Text });
// after
CompiledBinding.For(x => x.PreparedVM);
Defensive patterns

Strategy: validation

Validate before calling

// Reject member initialization (object initializers) in the binding lambda.
static bool HasMemberInit(Expression e) => e is MemberInitExpression;

Prevention

When it happens

Trigger: CompiledBinding.For(x => new ViewModel { Title = x.Title }) or any object initializer inside a compiled-binding lambda.

Common situations: Trying to construct a sub-object inline in the binding path instead of building it in the view-model.

Related errors


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