dotnet/wpf · error · XamlUnexpectedParseException
EmptyPropertyElement ::= EMPTYPROPERTYELEMENT.
Error message
EmptyPropertyElement ::= EMPTYPROPERTYELEMENT.
What it means
P_EmptyPropertyElement implements EmptyPropertyElement ::= EMPTYPROPERTYELEMENT. It throws XamlUnexpectedParseException if the scanner's current node is not an EMPTYPROPERTYELEMENT, i.e. the parser expected a self-closing property element but found a different node kind. The library throws this to enforce that this production is only invoked at the correct scanner state.
Solutions
- Correct the markup so the empty property element is truly self-closing (e.g. <Grid.RowDefinitions/>) at the reported position
- Re-run the scanner from a clean stream; do not reuse a partially consumed XamlXmlReader
- Verify no custom node-stream injection (XamlNodeList rewinding) is desynchronizing NodeType
Example fix
// before <Grid.RowDefinitions> </Grid.RowDefinitions> // after (or a fully-formed nonempty element) <Grid.RowDefinitions> <RowDefinition Height="Auto" /> </Grid.RowDefinitions>
Defensive patterns
Strategy: validation
Validate before calling
if (!xaml.TrimEnd().EndsWith("/>")) throw new InvalidOperationException("Expected self-closing property element"); Try / catch
try { reader.Read(); /* node loop */ } catch (System.Xaml.XamlParseException ex) { HandleParseFailure(ex.LineNumber, ex.LinePosition, ex.Message); } Prevention
- Write empty property elements as <Owner.Property/> when they have no content
- Verify scanner state only advances through the public XamlXmlReader API
- Round-trip markup through XamlXmlWriter to normalize node forms
When it happens
Trigger: Internal parser dispatch reaches P_EmptyPropertyElement (via P_PropertyElement) while _xamlScanner.NodeType != ScannerNodeType.EMPTYPROPERTYELEMENT — a parser/scanner desynchronization caused by malformed or non-canonical markup.
Common situations: Malformed XAML where a property element position contains a non-empty element or other token; custom IXamlXmlParser pipelines feeding nodes out of order; bugs in third-party markup that mimics property elements.
Related errors
- Element ::= . EmptyElement | ( StartElement ElementBody ).
- NonemptyPropertyElement ::= . PROPERTYELEMENT Content?…
- 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/92cbcb110528a4c4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs:351
{
yield return node;
}
break;
default:
throw new XamlUnexpectedParseException(_xamlScanner, nodeType,
PropertyElementRuleException);
}
}
///////////////////////////
// EmptyPropertyElement ::= EMPTYPROPERTYELEMENT
//
public IEnumerable<XamlNode> P_EmptyPropertyElement()
{
if (_xamlScanner.NodeType != ScannerNodeType.EMPTYPROPERTYELEMENT)
{
throw new XamlUnexpectedParseException(_xamlScanner, _xamlScanner.NodeType,
EmptyPropertyElementRuleException);
}
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)View on GitHub (pinned to 81131a70a4)