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
- Construct the object in the view-model and bind to that property.
- Use a converter that builds the object from the source value.
- 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
- Avoid object initializers in binding lambdas.
- Construct objects in the view-model.
- Use a converter when a new object must be built from a bound value.
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
- Invalid expression type in binding expression: {node.NodeTyp
- Invalid indexer in binding expression: {node.NodeType}.
- Invalid method call in binding expression: '{node.Method.Dec
- Catch blocks are not allowed in binding expressions.
- Dynamic expressions are not allowed in binding expressions.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/be0b93573d195272.
Report an issue: GitHub.