{"record":{"id":"6917d5a296ddedc0","repo":"dotnet/wpf","slug":"sr-format-sr-unknownattributeproperty-typeof","errorCode":null,"errorMessage":"SR.Format(SR.UnknownAttributeProperty, typeof(DependsOnAttribute).Name, doPropertyName, _name)","messagePattern":"SR\\.Format\\(SR\\.UnknownAttributeProperty, typeof\\(DependsOnAttribute\\)\\.Name, doPropertyName, _name\\)","errorType":"exception","errorClass":"XamlSchemaException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrProperty.cs","lineNumber":391,"sourceCode":"        }\n\n        private XamlProperty LookupDependsOn()\n        {\n            object obj = LookupCustomAttribute(typeof(DependsOnAttribute));\n            if (obj == null)\n            {\n                return null;\n            }\n            else\n            {\n                string doPropertyName = ((DependsOnAttribute)obj).Name;\n                XamlProperty xp = _declaringType.GetProperty(doPropertyName);\n                if (xp != null)\n                    return xp;\n                else\n                {\n                    string err = SR.Format(SR.UnknownAttributeProperty, typeof(DependsOnAttribute).Name, doPropertyName, _name);\n                    throw new XamlSchemaException(err);\n                }\n            }\n        }\n\n        protected virtual XamlType LookupTargetType()\n        {\n            return null;\n        }\n\n        private bool LookupIsAmbient()\n        {\n            object obj = LookupCustomAttribute(typeof(AmbientAttribute));\n            return (obj == null) ? false : true;\n        }\n\n        // ===========================\n\n        private bool CheckPropertyBit(BoolPropertyBits propertyBit)","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrProperty.cs#L373-L409","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Correct the string in [DependsOn(\"...\")] to the exact name of an existing property on the same type.","If the dependency moved to another class, remove the DependsOn attribute or re-point it at a property that exists on the declaring type.","Search the type for all DependsOn usages and validate each referenced name at build time with a unit test over the XAML schema."],"exampleFix":"// before\n[DependsOn(\"Backgroung\")]\npublic Color Foreground { get; set; }\n\n// after\n[DependsOn(\"Background\")]\npublic Color Foreground { get; set; }","handlingStrategy":"validation","validationCode":"// validate all DependsOn references at startup\nforeach (var p in type.GetProperties())\n    foreach (var d in p.GetCustomAttributes<DependsOnAttribute>())\n        if (type.GetProperty(d.Name) is null)\n            throw new InvalidOperationException($\"{p.Name}: DependsOn '{d.Name}' not found on {type.Name}\");","typeGuard":"bool IsValidDependsOn(Type t, string name) => t.GetProperty(name) != null;","tryCatchPattern":"try { var dep = property.DependsOn; }\ncatch (XamlSchemaException ex) { log(ex.Message); /* fix the attribute; DependsOn cannot be defaulted safely */ }","preventionTips":["Rename properties with IDE refactoring so DependsOn strings update","Write a build-time test validating every DependsOn target exists","Keep DependsOn strings next to the property they reference","Avoid hand-editing attribute strings without compiling"],"tags":["xaml","schema","depends-on","missing-member"],"backgroundTag":"resource-not-found","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}