{"record":{"id":"f30c8bdde2b65478","repo":"dotnet/wpf","slug":"0-is-not-a-valid-xaml-member-name","errorCode":null,"errorMessage":"'{0}' is not a valid XAML member name.","messagePattern":"'(.+?)' is not a valid XAML member name\\.","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs","lineNumber":569,"sourceCode":"            // Collect up all the attributes.\n            bool b = _xmlReader.MoveToFirstAttribute();\n\n            if (!b)\n            {\n                return;\n            }\n\n            List<XamlAttribute> list = new List<XamlAttribute>();\n            do\n            {\n                string xmlName = _xmlReader.Name;\n                string val = _xmlReader.Value;\n\n                XamlPropertyName propName = XamlPropertyName.Parse(xmlName);\n\n                if (propName is null)\n                {\n                    throw new XamlParseException(SR.Format(SR.InvalidXamlMemberName, xmlName));\n                }\n\n                XamlAttribute attr = new XamlAttribute(propName, val, _xmlLineInfo);\n\n                if (attr.Kind == ScannerAttributeKind.Namespace)\n                {\n                    EnqueuePrefixDefinition(attr);\n                }\n                else\n                {\n                    list.Add(attr);\n                }\n\n                b = _xmlReader.MoveToNextAttribute();\n            }\n            while (b);\n\n            PreprocessForTypeArguments(list);","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs#L551-L587","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Correct the attribute name at the reported line so it is a valid [prefix:]member form","Remove or fix attributes with empty or malformed local names","Regenerate the markup from the designer tool rather than hand-editing broken names"],"exampleFix":"// before (malformed member name)\n<Button :Content=\"Hi\" />\n// after\n<Button Content=\"Hi\" />","handlingStrategy":"validation","validationCode":"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 ')'); }","typeGuard":null,"tryCatchPattern":"try { LoadXaml(xaml); } catch (System.Xaml.XamlParseException ex) when (ex.Message.Contains(\"not a valid XAML member name\")) { Report(ex.Message); throw; }","preventionTips":["Avoid colons, spaces, or special characters in attribute names","Use only prefix:name or name attribute forms","Regenerate markup from tooling instead of hand-fixing corrupt attribute names"],"tags":["xaml","attributes","member-name","parsing"],"backgroundTag":"invalid-identifier-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}