{"record":{"id":"5e8e73263ce78530","repo":"dotnet/wpf","slug":"elementbody-attribute-propertyelement-content-endtag","errorCode":null,"errorMessage":"ElementBody ::= ATTRIBUTE* ( PropertyElement | Content )* . ENDTAG.","messagePattern":"ElementBody ::= ATTRIBUTE\\* \\( PropertyElement \\| Content \\)\\* \\. ENDTAG\\.","errorType":"exception","errorClass":"XamlUnexpectedParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs","lineNumber":303,"sourceCode":"                    if (!hasContent && hasTypeConverter && !isConstructable)\n                    {\n                        yield return Logic_StartInitProperty(currentType);\n                        yield return new XamlNode(XamlNodeType.Value, string.Empty);\n                        yield return Logic_EndMember();\n                    }\n\n                    doneWithElementContent = true;\n                    break;\n                default:\n                    doneWithElementContent = true;\n                    break;\n                }\n            }\n            while (!doneWithElementContent);\n\n            if (_xamlScanner.NodeType != ScannerNodeType.ENDTAG)\n            {\n                throw new XamlUnexpectedParseException(_xamlScanner, _xamlScanner.NodeType,\n                    ElementBodyRuleException);\n            }\n\n            yield return Logic_EndObject();\n            _xamlScanner.Read();\n            if (ProvideLineInfo)\n            {\n                yield return Logic_LineInfo();\n            }\n        }\n\n        ///////////////////////////\n        //  PropertyElement ::= EmptyPropertyElement | NonemptyPropertyElement\n        //\n        public IEnumerable<XamlNode> P_PropertyElement()\n        {\n            ScannerNodeType nodeType = _xamlScanner.NodeType;\n","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs#L285-L321","documentation":"XamlPullParser.P_ElementBody implements `ElementBody ::= ATTRIBUTE* (PropertyElement | Content)* ENDTAG`. After consuming attributes, property elements, and content, it requires the current scanner node to be ENDTAG (</Tag>); if it is not, it throws XamlUnexpectedParseException with the ElementBody rule. This detects elements that end without a proper closing tag before the parser emits its EndObject node.","triggerScenarios":"XAML where an element's content/property elements end but no matching </Tag> follows — e.g. mismatched tag names, an unclosed child element swallowing the parent's end tag, or an EOF reached before ENDTAG during XamlReader.Load.","commonSituations":"Hand-edited XAML with mismatched or missing closing tags; string-generated markup missing an end tag; merging XAML fragments where a nested element was not fully closed; truncation of the XAML stream mid-element.","solutions":["Add the missing </Tag> so every open element has a matching end tag.","Check tag-name spelling/casing — mismatched names prevent ENDTAG recognition.","Validate the document as XML (xmllint or IDE validation) before XamlReader.Load.","If building XAML programmatically, ensure each StartElement is paired with an end; consider emitting self-closing <Tag/> for empty elements."],"exampleFix":"<!-- before -->\n<StackPanel>\n  <TextBlock Text=\"Hi\" />\n\n<!-- after -->\n<StackPanel>\n  <TextBlock Text=\"Hi\" />\n</StackPanel>","handlingStrategy":"validation","validationCode":"// Detect unclosed elements before Load\nvar settings = new System.Xml.XmlReaderSettings { ConformanceLevel = System.Xml.ConformanceLevel.Document };\nusing (var xr = System.Xml.XmlReader.Create(new System.IO.StringReader(xaml), settings)) { while (xr.Read()) { } } // throws on mismatched/missing end tags","typeGuard":null,"tryCatchPattern":"try { return XamlReader.Parse(xaml); } catch (XamlUnexpectedParseException ex) { Log($\"Missing ENDTAG near {ex.LineNumber}:{ex.LinePosition}\"); return null; }","preventionTips":["Validate XML well-formedness first — it catches missing end tags cheaply","Emit self-closing <Tag/> for empty elements in generators","Never concatenate XAML fragments without closing all tags"],"tags":["xaml","parser","grammar","unclosed-tag"],"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-21T21:30:21.729Z"}