AvaloniaUI/Avalonia · error · ExpressionParseException
Invalid attached property name.
Error message
Invalid attached property name.
What it means
Thrown by ParseAttachedProperty when the parser has read a type name inside parentheses — the '(Owner' part of an attached-property path '(Owner.Property)' — and the next token is neither '.' (beginning the property name) nor ')' (making it a type cast). Avalonia treats '(Type)' as a cast and '(Type.Property)' as an attached property, so any other continuation after the type name is invalid.
Source
Thrown at src/Avalonia.Base/Data/Core/Parsers/BindingExpressionGrammar.cs:231
}
private static State ParseAttachedProperty(
#if NET7SDK
scoped
#endif
ref CharacterReader r, List<INode> nodes, bool acceptsNull)
{
var (ns, owner) = ParseTypeName(ref r);
if(!r.End && r.TakeIf(')'))
{
nodes.Add(new TypeCastNode() { Namespace = ns, TypeName = owner });
return State.AfterMember;
}
if (r.End || !r.TakeIf('.'))
{
throw new ExpressionParseException(r.Position, "Invalid attached property name.");
}
var name = r.ParseIdentifier();
if (name.Length == 0)
{
throw new ExpressionParseException(r.Position, "Attached Property name expected after '.'.");
}
if (r.End || !r.TakeIf(')'))
{
throw new ExpressionParseException(r.Position, "Expected ')'.");
}
nodes.Add(new AttachedPropertyNameNode
{
AcceptsNull = acceptsNull,
Namespace = ns,View on GitHub (pinned to 11c5427268)
Solutions
- Verify the attached property uses the correct compact syntax: (NamespacePrefix.TypeName.PropertyName) with a '.' between type and property.
- If intending a type cast, ensure the type name is followed by ')' with no trailing characters before the close paren.
- Check the Column position in the exception to locate where the parser diverged from expected syntax.
Example fix
<!-- before: missing '.' between type and property -->
<TextBox Text="{Binding (GridRow)}" />
<!-- after: correct attached property syntax -->
<TextBox Text="{Binding (Grid.Row)}" /> Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate attached-property or cast syntax in a binding path
static void ValidateAttachedPropertySyntax(string path)
{
// Check that any '(' is followed by a type name and then either '.' (property) or ')' (cast)
var parenPattern = new System.Text.RegularExpressions.Regex(
@"\([A-Za-z_][A-Za-z0-9_]*(?::[A-Za-z_][A-Za-z0-9_]*)?[.)]");
// Find all '(' in the path and verify the following tokens
for (int i = 0; i < path.Length; i++)
{
if (path[i] == '(')
{
// Next char must be a letter or underscore (type name start)
if (i + 1 >= path.Length || !char.IsLetter(path[i + 1]) && path[i + 1] != '_')
throw new ArgumentException(
$"Invalid character after '(' at position {i} in binding path '{path}'");
}
}
} Try / catch
try
{
var binding = new Binding(path);
}
catch (ExpressionParseException ex) when (ex.Message.Contains("Invalid attached property name"))
{
logger.LogError($"Attached property syntax error at column {ex.Column}: expected '(Type.Property)' or '(Type)'");
} Prevention
- Memorize the two valid parenthesized forms: '(Owner.Property)' for attached properties and '(Owner)' for casts.
- Use an IDE snippet or live template for attached-property binding paths to avoid manual typing errors.
- Validate XAML binding paths at design time using the Avalonia XAML compiler.
When it happens
Trigger: Writing '(Grid' at end of string, or '(Grid' followed by a character that is not '.' or ')' such as '(Grid#myButton'. The parser has already consumed the type name via ParseIdentifier and now expects the attached-property separator or the cast-closing paren.
Common situations: Mistyping the attached-property syntax in a XAML binding path; forgetting whether to use '(' or '[' for an attached property vs. indexer; transitioning from XAML's full attached-property XML syntax (Grid.Row) to the compact binding mini-language '(Grid.Row)' and omitting the dot.
Related errors
- Attached Property name expected after '.'.
- Expected ')'.
- Unexpected end of expression.
- Indexer may not be empty.
- Element name expected after '#'.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/5f1612ae4476388e.
Report an issue: GitHub.