{"record":{"id":"be0b93573d195272","repo":"AvaloniaUI/Avalonia","slug":"member-assignments-not-supported-in-binding-expres","errorCode":null,"errorMessage":"Member assignments not supported in binding expressions.","messagePattern":"Member assignments not supported in binding expressions\\.","errorType":"validation","errorClass":"ExpressionParseException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs","lineNumber":250,"sourceCode":"\n    protected override Expression VisitLabel(LabelExpression node)\n    {\n        throw new ExpressionParseException(0, $\"Invalid expression type in binding expression: {node.NodeType}.\");\n    }\n\n    protected override Expression VisitListInit(ListInitExpression node)\n    {\n        throw new ExpressionParseException(0, $\"Invalid expression type in binding expression: {node.NodeType}.\");\n    }\n\n    protected override Expression VisitLoop(LoopExpression node)\n    {\n        throw new ExpressionParseException(0, $\"Invalid expression type in binding expression: {node.NodeType}.\");\n    }\n\n    protected override MemberAssignment VisitMemberAssignment(MemberAssignment node)\n    {\n        throw new ExpressionParseException(0, \"Member assignments not supported in binding expressions.\");\n    }\n\n    protected override Expression VisitSwitch(SwitchExpression node)\n    {\n        throw new ExpressionParseException(0, $\"Invalid expression type in binding expression: {node.NodeType}.\");\n    }\n\n    protected override Expression VisitTry(TryExpression node)\n    {\n        throw new ExpressionParseException(0, $\"Invalid expression type in binding expression: {node.NodeType}.\");\n    }\n\n    protected override Expression VisitTypeBinary(TypeBinaryExpression node)\n    {\n        throw new ExpressionParseException(0, $\"Invalid expression type in binding expression: {node.NodeType}.\");\n    }\n\n    private Expression Add(Expression? instance, Expression expression, Action<CompiledBindingPathBuilder> build)","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs#L232-L268","documentation":"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.","triggerScenarios":"CompiledBinding.For(x => new ViewModel { Title = x.Title }) or any object initializer inside a compiled-binding lambda.","commonSituations":"Trying to construct a sub-object inline in the binding path instead of building it in the view-model.","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."],"exampleFix":"// before\nCompiledBinding.For(x => new VM { Text = x.Text });\n// after\nCompiledBinding.For(x => x.PreparedVM);","handlingStrategy":"validation","validationCode":"// Reject member initialization (object initializers) in the binding lambda.\nstatic bool HasMemberInit(Expression e) => e is MemberInitExpression;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["compiled-binding","expression-tree","binding"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}