{"record":{"id":"2d7c89b52fff4349","repo":"dotnet/wpf","slug":"propertyelement-emptypropertyelement-nonemptypropertyelement","errorCode":null,"errorMessage":"PropertyElement ::= EmptyPropertyElement | NonemptyPropertyElement","messagePattern":"PropertyElement ::= EmptyPropertyElement \\| NonemptyPropertyElement","errorType":"exception","errorClass":"XamlUnexpectedParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs","lineNumber":339,"sourceCode":"\n            switch (nodeType)\n            {\n                case ScannerNodeType.EMPTYPROPERTYELEMENT:\n                    foreach (XamlNode node in P_EmptyPropertyElement())\n                    {\n                        yield return node;\n                    }\n\n                    break;\n                case ScannerNodeType.PROPERTYELEMENT:\n                    foreach (XamlNode node in P_NonemptyPropertyElement())\n                    {\n                        yield return node;\n                    }\n\n                    break;\n                default:\n                    throw new XamlUnexpectedParseException(_xamlScanner, nodeType,\n                        PropertyElementRuleException);\n            }\n        }\n\n        ///////////////////////////\n        //  EmptyPropertyElement ::= EMPTYPROPERTYELEMENT\n        //\n        public IEnumerable<XamlNode> P_EmptyPropertyElement()\n        {\n            if (_xamlScanner.NodeType != ScannerNodeType.EMPTYPROPERTYELEMENT)\n            {\n                throw new XamlUnexpectedParseException(_xamlScanner, _xamlScanner.NodeType,\n                    EmptyPropertyElementRuleException);\n            }\n\n            yield return Logic_StartMember(_xamlScanner.PropertyElement);\n            yield return Logic_EndMember();\n            _xamlScanner.Read();","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs#L321-L357","documentation":"XamlPullParser's P_PropertyElement implements the grammar rule PropertyElement ::= EmptyPropertyElement | NonemptyPropertyElement and dispatches on the scanner's current node type. If the scanner produces a node type that is neither EMPTYPROPERTYELEMENT nor PROPERTYELEMENT where a property element must appear, the parser throws XamlUnexpectedParseException. This means the XAML markup is structurally invalid at that position.","triggerScenarios":"Calling XamlXmlReader/XamlPullParser over markup where a nested element inside a property element is not a well-formed property element (e.g. stray text or an unexpected node kind between <x:Members> style property elements). Reached via P_ElementBody → P_PropertyElement when the scanner's NodeType falls into the default (unexpected) case of the switch.","commonSituations":"Hand-edited XAML with mismatched or mistyped tags; markup generated by a tool that emits invalid nesting; copying XAML fragments between documents where a property-element position receives something else (attribute-style content, text, or an end tag).","solutions":["Fix the XAML so the element inside the property element is a legal property element (<Owner.Property>...</Owner.Property> or self-closing <Owner.Property/>)","Validate the markup with an XML/XSD validator before feeding it to the XAML reader to catch nesting errors early","Check for stray text nodes or misplaced end tags at the reported line/position from the parse exception"],"exampleFix":"// before (invalid: text where a property element is required)\n<Button><Click>Handler</Click></Button>\n// after\n<Button Click=\"Handler\" />","handlingStrategy":"validation","validationCode":"using var xr = System.Xml.XmlReader.Create(path); try { while (xr.Read()) { } } catch (System.Xml.XmlException ex) { throw new InvalidOperationException($\"Malformed XAML at {ex.LineNumber}:{ex.LinePosition}\", ex); }","typeGuard":"static bool IsWellFormedXml(string xaml) { try { var d = new System.Xml.XmlDocument(); d.LoadXml(xaml); return true; } catch { return false; } }","tryCatchPattern":"try { ParseXaml(stream); } catch (System.Xaml.XamlParseException ex) { Log($\"XAML structure invalid at {ex.LineNumber}:{ex.LinePosition}: {ex.Message}\"); throw; }","preventionTips":["Validate markup with an XML parser before XAML parsing","Keep property elements as Owner.Property tags only — no stray text nodes inside","Use the XAML designer or a schema-aware editor to author markup","Never reuse a partially consumed XamlXmlReader"],"tags":["xaml","parser","wpf","grammar"],"backgroundTag":"xml-parse-error","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}