dotnet/wpf · error · InvalidOperationException

SR.Format(SR.PropertyPathNoOwnerType, ownerName)

Error message

SR.Format(SR.PropertyPathNoOwnerType, ownerName)

What it means

ResolvePropertyName throws this InvalidOperationException when attached-property syntax '(TypeName.PropertyName)' is used but the owner type name cannot be resolved to a System.Type via GetTypeFromName (no matching type found through the ParserContext namespace mappings). Without an owner type the attached property cannot be resolved.

Solutions

  1. Fully qualify the type with a registered xmlns prefix, e.g. '(local:MyClass.MyAttachedProperty)', and ensure the prefix is added to ParserContext.XmlnsDictionary
  2. Add the missing namespace mapping to XmlnsDictionary, e.g. ctx.XmlnsDictionary["local"] = "clr-namespace:MyApp;assembly=MyApp"
  3. Correct the type-name spelling/namespace in the path string
  4. Use the DependencyProperty object directly (e.g. Grid.RowProperty) via PathParameters instead of name-based resolution

Example fix

// before
var ctx = new ParserContext();
var path = new PropertyPath("(MyClass.AttachedProp)", ctx); // type unresolvable
// after
ctx.XmlnsDictionary["local"] = "clr-namespace:MyApp;assembly=MyApp";
var path = new PropertyPath("(local:MyClass.AttachedProp)", ctx);
Defensive patterns

Strategy: validation

Validate before calling

// ensure the prefix resolves before building the path
bool prefixKnown = parserContext.XmlnsDictionary.Contains("local");
bool typeExists = AppDomain.CurrentDomain.GetAssemblies()
    .SelectMany(a => { try { return a.GetTypes(); } catch { return Type.EmptyTypes; } })
    .Any(t => t.Name == "MyClass");

Type guard

bool CanResolveType(string name, ParserContext ctx) =>
    !name.Contains(':') || (ctx.XmlnsDictionary[name.Split(':')[0]] != null);

Try / catch

try { var path = new PropertyPath("(local:MyClass.AttachedProp)", ctx); }
catch (InvalidOperationException ex) when (ex.Message.Contains("owner type")) { /* register xmlns or fix type name */ }

Prevention

When it happens

Trigger: Path string '(MyType.MyAttachedProperty)' where MyType has no xmlns prefix mapping and cannot be resolved; an xmlns prefix that is not registered in the ParserContext.XmlnsDictionary; a misspelled or renamed type name in the path.

Common situations: XAML binding paths using attached properties (e.g. '(Grid.Row)') where the namespace prefix is missing from XmlnsDictionary; type moved to another namespace/assembly after a refactor; hand-built ParserContext missing standard WPF xmlns mappings.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs:577

                else if (throwOnError)
                    throw new InvalidOperationException(SR.Format(SR.PathParametersIndexOutOfRange, index, PathParameters.Count));
                else return null;
            }

            // handle attached-property syntax:  (TypeName.PropertyName)
            if (IsPropertyReference(name))
            {
                name = name.Substring(1, name.Length-2);

                int lastIndex = name.LastIndexOf('.');
                if (lastIndex >= 0)
                {
                    // attached property - get the owner type
                    propertyName = name.Substring(lastIndex + 1).Trim();
                    string ownerName = name.Substring(0, lastIndex).Trim();
                    ownerType = GetTypeFromName(ownerName, context);
                    if (ownerType == null && throwOnError)
                        throw new InvalidOperationException(SR.Format(SR.PropertyPathNoOwnerType, ownerName));
                }
                else
                {
                    // simple name in parens - just strip the parens
                    propertyName = name;
                }
            }

            if (ownerType != null)
            {
                // get an appropriate accessor from the ownerType and propertyName.
                // We prefer accessors in a certain order, defined below.
                object accessor;

                // 1. DependencyProperty on the given type.
                accessor = DependencyProperty.FromName(propertyName, ownerType);

                // 2. PropertyDescriptor from item's custom lookup.

View on GitHub (pinned to 81131a70a4)