dotnet/wpf · error · XamlSchemaException

SR.Format(SR.UnknownAttributeProperty…

Error message

SR.Format(SR.UnknownAttributeProperty, typeof(DependsOnAttribute).Name, doPropertyName, _name)

What it means

ClrProperty.LookupDependsOn resolves the property named by a [DependsOn("...")] attribute. If the named property does not exist on the declaring type, the schema throws XamlSchemaException reporting the DependsOn attribute, the unknown property name, and the attributed member. It exists because a DependsOn reference to a nonexistent member would silently produce wrong initialization order.

Solutions

  1. Correct the string in [DependsOn("...")] to the exact name of an existing property on the same type.
  2. If the dependency moved to another class, remove the DependsOn attribute or re-point it at a property that exists on the declaring type.
  3. Search the type for all DependsOn usages and validate each referenced name at build time with a unit test over the XAML schema.

Example fix

// before
[DependsOn("Backgroung")]
public Color Foreground { get; set; }

// after
[DependsOn("Background")]
public Color Foreground { get; set; }
Defensive patterns

Strategy: validation

Validate before calling

// validate all DependsOn references at startup
foreach (var p in type.GetProperties())
    foreach (var d in p.GetCustomAttributes<DependsOnAttribute>())
        if (type.GetProperty(d.Name) is null)
            throw new InvalidOperationException($"{p.Name}: DependsOn '{d.Name}' not found on {type.Name}");

Type guard

bool IsValidDependsOn(Type t, string name) => t.GetProperty(name) != null;

Try / catch

try { var dep = property.DependsOn; }
catch (XamlSchemaException ex) { log(ex.Message); /* fix the attribute; DependsOn cannot be defaulted safely */ }

Prevention

When it happens

Trigger: A property decorated with [DependsOn("SomeName")] where _declaringType.GetProperty("SomeName") returns null — i.e., the DependsOn string does not match any property on the declaring XamlType.

Common situations: Renaming a property without updating the DependsOn string; a typo in the DependsOn argument; moving a property to a different class so the dependency is no longer on the same declaring type.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrProperty.cs:391

        }

        private XamlProperty LookupDependsOn()
        {
            object obj = LookupCustomAttribute(typeof(DependsOnAttribute));
            if (obj == null)
            {
                return null;
            }
            else
            {
                string doPropertyName = ((DependsOnAttribute)obj).Name;
                XamlProperty xp = _declaringType.GetProperty(doPropertyName);
                if (xp != null)
                    return xp;
                else
                {
                    string err = SR.Format(SR.UnknownAttributeProperty, typeof(DependsOnAttribute).Name, doPropertyName, _name);
                    throw new XamlSchemaException(err);
                }
            }
        }

        protected virtual XamlType LookupTargetType()
        {
            return null;
        }

        private bool LookupIsAmbient()
        {
            object obj = LookupCustomAttribute(typeof(AmbientAttribute));
            return (obj == null) ? false : true;
        }

        // ===========================

        private bool CheckPropertyBit(BoolPropertyBits propertyBit)

View on GitHub (pinned to 81131a70a4)