dotnet/wpf · error · XamlUnexpectedParseException
NonemptyPropertyElement ::= . PROPERTYELEMENT Content?…
Error message
NonemptyPropertyElement ::= . PROPERTYELEMENT Content? ENDTAG.
What it means
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.
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
Example fix
// before (empty tag used where content follows) <Window.Resources/> <SolidColorBrush x:Key="b"/> // after <Window.Resources> <SolidColorBrush x:Key="b"/> </Window.Resources>
Defensive patterns
Strategy: validation
Validate before calling
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"); Try / catch
try { LoadXaml(xamlText); } catch (System.Xaml.XamlParseException ex) { Report(ex.LineNumber, ex.LinePosition, ex.Message); throw; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Element ::= . EmptyElement | ( StartElement ElementBody ).
- EmptyPropertyElement ::= EMPTYPROPERTYELEMENT.
- PropertyElement ::= EmptyPropertyElement |…
- ElementBody ::= ATTRIBUTE* ( PropertyElement | Content )* …
- EmptyElement ::= . EMPTYELEMENT DIRECTIVE* ATTRIBUTE*.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/805c3788574185a5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs:371
}
yield return Logic_StartMember(_xamlScanner.PropertyElement);
yield return Logic_EndMember();
_xamlScanner.Read();
if (ProvideLineInfo)
{
yield return Logic_LineInfo();
}
}
///////////////////////////
// NonemptyPropertyElement ::= PROPERTYELEMENT PropertyContent* ENDTAG
//
public IEnumerable<XamlNode> P_NonemptyPropertyElement()
{
if (_xamlScanner.NodeType != ScannerNodeType.PROPERTYELEMENT)
{
throw new XamlUnexpectedParseException(_xamlScanner, _xamlScanner.NodeType,
NonemptyPropertyElementRuleException);
}
yield return Logic_StartMember(_xamlScanner.PropertyElement);
_xamlScanner.Read();
if (ProvideLineInfo)
{
yield return Logic_LineInfo();
}
bool doingPropertyContent = true;
do
{
ScannerNodeType nodeType = _xamlScanner.NodeType;
switch (nodeType)
{
case ScannerNodeType.PREFIXDEFINITION:
case ScannerNodeType.ELEMENT:View on GitHub (pinned to 81131a70a4)