dotnet/wpf · error · XamlParseException

' ' is not a valid XAML member name.

Error message

'{0}' is not a valid XAML member name.

What it means

During attribute preprocessing the scanner parses each XML attribute name via XamlPropertyName.Parse. If the name is not a valid XAML member name (e.g. malformed attached-property or directive syntax), Parse returns null and the scanner throws XamlParseException with SR.InvalidXamlMemberName ('{0}' is not a valid XAML member name). The library throws this because it cannot map the attribute to any member/directive and cannot proceed building the node stream.

Solutions

  1. Correct the attribute name at the reported line so it is a valid [prefix:]member form
  2. Remove or fix attributes with empty or malformed local names
  3. Regenerate the markup from the designer tool rather than hand-editing broken names

Example fix

// before (malformed member name)
<Button :Content="Hi" />
// after
<Button Content="Hi" />
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidMemberName(string name) { if (string.IsNullOrWhiteSpace(name)) return false; var parts = name.Split(':'); if (parts.Length > 2) return false; var local = parts[^1]; return local.Length > 0 && local.All(c => char.IsLetterOrDigit(c) || c is '_' or '.' or '(' or ')'); }

Try / catch

try { LoadXaml(xaml); } catch (System.Xaml.XamlParseException ex) when (ex.Message.Contains("not a valid XAML member name")) { Report(ex.Message); throw; }

Prevention

When it happens

Trigger: An XML attribute on an object element has a name XamlPropertyName.Parse cannot accept — e.g. empty local name, malformed prefix:member syntax, illegal characters, or a malformed x: directive name — encountered in PreprocessAttributes during ReadObjectElement/ReadPropertyElement.

Common situations: Typos in attribute names (leading/trailing colons, double colons); XML-invalid characters introduced by generators; corrupted markup after manual merge; directives misspelled (x:Shareds instead of x:Shared is fine as unknown, but structurally broken names fail here).

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/f30c8bdde2b65478. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs:569

            // Collect up all the attributes.
            bool b = _xmlReader.MoveToFirstAttribute();

            if (!b)
            {
                return;
            }

            List<XamlAttribute> list = new List<XamlAttribute>();
            do
            {
                string xmlName = _xmlReader.Name;
                string val = _xmlReader.Value;

                XamlPropertyName propName = XamlPropertyName.Parse(xmlName);

                if (propName is null)
                {
                    throw new XamlParseException(SR.Format(SR.InvalidXamlMemberName, xmlName));
                }

                XamlAttribute attr = new XamlAttribute(propName, val, _xmlLineInfo);

                if (attr.Kind == ScannerAttributeKind.Namespace)
                {
                    EnqueuePrefixDefinition(attr);
                }
                else
                {
                    list.Add(attr);
                }

                b = _xmlReader.MoveToNextAttribute();
            }
            while (b);

            PreprocessForTypeArguments(list);

View on GitHub (pinned to 81131a70a4)