{"record":{"id":"871758a7dc038b96","repo":"AvaloniaUI/Avalonia","slug":"goto-expressions-are-not-supported-in-binding-expr","errorCode":null,"errorMessage":"Goto expressions are not supported in binding expressions.","messagePattern":"Goto expressions are not supported in binding expressions\\.","errorType":"validation","errorClass":"ExpressionParseException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs","lineNumber":225,"sourceCode":"\n    protected override Expression VisitConditional(ConditionalExpression node)\n    {\n        throw new ExpressionParseException(0, $\"Invalid expression type in binding expression: {node.NodeType}.\");\n    }\n\n    protected override Expression VisitDynamic(DynamicExpression node)\n    {\n        throw new ExpressionParseException(0, \"Dynamic expressions are not allowed in binding expressions.\");\n    }\n\n    protected override ElementInit VisitElementInit(ElementInit node)\n    {\n        throw new ExpressionParseException(0, \"Element init expressions are not valid in a binding expression.\");\n    }\n\n    protected override Expression VisitGoto(GotoExpression node)\n    {\n        throw new ExpressionParseException(0, \"Goto expressions are not supported in binding expressions.\");\n    }\n\n    protected override Expression VisitInvocation(InvocationExpression node)\n    {\n        throw new ExpressionParseException(0, $\"Invalid expression type in binding expression: {node.NodeType}.\");\n    }\n\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)","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs#L207-L243","documentation":"BindingExpressionVisitor walks a compiled-binding lambda (expression tree) and only accepts a restricted path subset: property access, indexers, casts, NOT, StreamBinding and delegate creation. VisitGoto rejects GotoExpression, which the C# compiler emits for `return`, `break`, `continue` and `goto` inside expression trees. Control flow is not part of a binding path, so it throws ExpressionParseException during BuildPath.","triggerScenarios":"Writing a block-bodied compiled-binding lambda such as CompiledBinding.For(x => { return x.Item.Text; }), or building an expression tree programmatically that contains a GotoExpression (return/break/continue) and passing it to the compiled-binding path builder.","commonSituations":"Converting a method body or LINQ query into a binding lambda; using statement-bodied lambdas; libraries that synthesize expression trees with control-flow lowering.","solutions":["Rewrite the binding lambda as a single expression-bodied member access chain: x => x.Item.Text.","Remove return/break/continue/goto from the compiled-binding lambda.","Keep binding lambdas limited to property/indexer/cast/StreamBinding operations; move any logic into the view-model."],"exampleFix":"// before\nCompiledBinding.For(x => { return x.Item.Text; });\n// after\nCompiledBinding.For(x => x.Item.Text);","handlingStrategy":"validation","validationCode":"// Compiled-binding lambdas must be expression-bodied single chains.\n// Reject lambdas whose Body is not a supported node type before parsing:\nstatic bool IsValidBindingBody(Expression body) => body switch\n{\n    MemberExpression or IndexExpression or UnaryExpression\n        or MethodCallExpression or ParameterExpression => true,\n    _ => false,\n};\n// Then only pass lambdas that satisfy this to CompiledBinding.For.","typeGuard":null,"tryCatchPattern":"try { var path = BindingExpressionVisitor<TIn>.BuildPath<TOut>(expr); }\ncatch (ExpressionParseException ex)\n{\n    // log and fall back to a simpler binding expression\n}","preventionTips":["Keep compiled-binding lambdas as single expression-bodied member chains.","Never use statement bodies, return/break/continue or block syntax in a binding lambda.","Run binding expressions through a design-time/XAML compiler check so malformed paths fail at build, not runtime."],"tags":["compiled-binding","expression-tree","linq","binding"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}