{"record":{"id":"805c3788574185a5","repo":"dotnet/wpf","slug":"nonemptypropertyelement-propertyelement-content-endtag","errorCode":null,"errorMessage":"NonemptyPropertyElement ::= . PROPERTYELEMENT Content? ENDTAG.","messagePattern":"NonemptyPropertyElement ::= \\. 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":371,"sourceCode":"            }\n\n            yield return Logic_StartMember(_xamlScanner.PropertyElement);\n            yield return Logic_EndMember();\n            _xamlScanner.Read();\n            if (ProvideLineInfo)\n            {\n                yield return Logic_LineInfo();\n            }\n        }\n\n        ///////////////////////////\n        //  NonemptyPropertyElement ::= PROPERTYELEMENT PropertyContent* ENDTAG\n        //\n        public IEnumerable<XamlNode> P_NonemptyPropertyElement()\n        {\n            if (_xamlScanner.NodeType != ScannerNodeType.PROPERTYELEMENT)\n            {\n                throw new XamlUnexpectedParseException(_xamlScanner, _xamlScanner.NodeType,\n                    NonemptyPropertyElementRuleException);\n            }\n\n            yield return Logic_StartMember(_xamlScanner.PropertyElement);\n            _xamlScanner.Read();\n            if (ProvideLineInfo)\n            {\n                yield return Logic_LineInfo();\n            }\n\n            bool doingPropertyContent = true;\n            do\n            {\n                ScannerNodeType nodeType = _xamlScanner.NodeType;\n                switch (nodeType)\n                {\n                case ScannerNodeType.PREFIXDEFINITION:\n                case ScannerNodeType.ELEMENT:","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs#L353-L389","documentation":"P_NonemptyPropertyElement implements NonemptyPropertyElement ::= PROPERTYELEMENT Content? ENDTAG and requires the scanner to be positioned on a PROPERTYELEMENT start token when invoked. If _xamlScanner.NodeType is not ScannerNodeType.PROPERTYELEMENT it throws XamlUnexpectedParseException. This guards the entry state of the nonempty property-element production.","triggerScenarios":"P_PropertyElement dispatches to P_NonemptyPropertyElement while the scanner is not on a PROPERTYELEMENT node — malformed markup or a desynchronized reader state at the point where a non-empty property element must begin.","commonSituations":"XAML where an empty element was written as a container (or vice versa); tool-generated markup with wrong tag forms; manually re-reading a XamlXmlReader after it already advanced past the element.","solutions":["Make the property element a proper start tag with matching end tag at the reported location","Do not rewind or partially consume the reader between parses; create a fresh XamlXmlReader per parse","Run an XML well-formedness check on the source before XAML parsing"],"exampleFix":"// before (empty tag used where content follows)\n<Window.Resources/>\n  <SolidColorBrush x:Key=\"b\"/>\n// after\n<Window.Resources>\n  <SolidColorBrush x:Key=\"b\"/>\n</Window.Resources>","handlingStrategy":"validation","validationCode":"bool matches = System.Text.RegularExpressions.Regex.IsMatch(fragment, \"<\\\\w+[.:][^/>]+>\\\\s*(<.*?>\\\\s*)*</\\\\w+[.:][^>]+>\"); if (!matches) throw new InvalidOperationException(\"Property element must be a proper start/end tag pair\");","typeGuard":null,"tryCatchPattern":"try { LoadXaml(xamlText); } catch (System.Xaml.XamlParseException ex) { Report(ex.LineNumber, ex.LinePosition, ex.Message); throw; }","preventionTips":["Ensure containers with children are not self-closed (<X><child/></X>, not <X/><child/>)","Run XSD/designer validation on generated markup","Create a fresh reader per parse; never rewind mid-stream"],"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-21T21:30:21.729Z"}