dotnet/wpf · error · XamlInternalException

SR.Format(SR.ParentlessPropertyElement, propName.ScopedName)

Error message

SR.Format(SR.ParentlessPropertyElement, propName.ScopedName)

What it means

GetDottedProperty resolves dotted (property-element) names like <foo.bar/>. If the enclosing tag type cannot be determined (tagType is null), it throws XamlInternalException with ParentlessPropertyElement carrying the scoped property name — the parser hit a property element with no owning type in scope.

Solutions

  1. Fix the markup so the property element is nested inside its owning object element.
  2. Ensure the document has a valid root object element before any property elements.
  3. If parsing fragments, wrap them in a valid parent element first.
  4. Catch XamlParseException/XamlInternalException during parse and surface the file/line for author correction.

Example fix

// before (malformed XAML)
<Window><Window.Title>...</Window.Title></Window> <!-- misplaced: root wrapper missing -->
// after
<Window xmlns="..."><Window.Title>...</Window.Title></Window> <!-- property element inside owner -->
Defensive patterns

Strategy: validation

Validate before calling

// pre-parse check: every dotted property element must be inside an object element
if (xml.Descendants().Any(e => e.Name.LocalName.Contains('.') && e.Parent == null))
    throw new XamlParseException("Property element at document root has no owner");

Type guard

bool HasOwnerType(XamlType tagType) => tagType != null;

Try / catch

try { parser.Load(xaml); }
catch (XamlInternalException ex) { // property element without owner type — fix markup nesting
  throw new FormatException("Malformed XAML: " + ex.Message, ex); }

Prevention

When it happens

Trigger: XAML parsing reaches a dotted property element (e.g. <Grid.Row> syntax internally) when no current object type is available, typically with malformed markup such as a property element appearing outside/before its owner element.

Common situations: Hand-edited XAML with a property element at the document root or before the opening object tag; tooling-generated XAML with mismatched nesting; programmatic parsing of fragment XAML lacking a root object.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/cc6be9853ac49ffb. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlContext.cs:79

            return IsVisible(member, null) ? member : null;
        }

        /// <summary>
        /// Resolves a property of the form 'Foo.Bar' or 'a:Foo.Bar', in
        /// in the context of a parent tag.  The parent tagType may or may not
        /// be covariant with the ownerType.  In the case of dotted attribute
        /// syntax, the namespace my be passed in.
        /// </summary>
        /// <param name="tagType">The xamlType of the enclosing Tag</param>
        /// <param name="tagNamespace">The namespace of the enclosing Tag</param>
        /// <param name="propName">The dotted name of the property</param>
        /// <param name="tagIsRoot">Whether the tag is the root of the document</param>
        /// <returns></returns>
        public XamlMember GetDottedProperty(XamlType tagType, string tagNamespace, XamlPropertyName propName, bool tagIsRoot)
        {
            if (tagType is null)
            {
                throw new XamlInternalException(SR.Format(SR.ParentlessPropertyElement, propName.ScopedName));
            }

            XamlMember property = null;
            XamlType ownerType = null;
            string ns = ResolveXamlNameNS(propName);
            if (ns is null)
            {
                throw new XamlParseException(SR.Format(SR.PrefixNotFound, propName.Prefix));
            }

            XamlType rootTagType = tagIsRoot ? tagType : null;

            // If we have <foo x:TA="" foo.bar=""/> we want foo in foo.bar to match the tag
            // type since there is no way to specify generic syntax in dotted property notation
            // If that fails, then we fall back to the non-generic case below.
            bool ownerTypeMatchesGenericTagType = false;
            if (tagType.IsGeneric)
            {

View on GitHub (pinned to 81131a70a4)