{"record":{"id":"7c89c2e5994fdc94","repo":"dotnet/wpf","slug":"sr-format-sr-toomanyattributes-declaringtype-name-name","errorCode":null,"errorMessage":"SR.Format(SR.TooManyAttributes, DeclaringType.Name, Name, attrType.Name)","messagePattern":"SR\\.Format\\(SR\\.TooManyAttributes, DeclaringType\\.Name, Name, attrType\\.Name\\)","errorType":"exception","errorClass":"XamlSchemaException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrProperty.cs","lineNumber":307,"sourceCode":"\n        // ==============================================\n\n        protected virtual Type LookupSystemTypeOfProperty()\n        {\n            return ClrBindingPropertyInfo.PropertyType;\n        }\n\n        private object LookupCustomAttribute(Type attrType)\n        {\n            object[] objs = LookupCustomAttributes(attrType);\n            if (objs.Length == 0)\n            {\n                return null;\n            }\n            if (objs.Length > 1)\n            {\n                string message = SR.Format(SR.TooManyAttributes, DeclaringType.Name, Name, attrType.Name);\n                throw new XamlSchemaException(message);\n            }\n            return objs[0];\n        }\n\n        protected virtual object[] LookupCustomAttributes(Type attrType)\n        {\n            return ClrBindingPropertyInfo.GetCustomAttributes(attrType, true);\n        }\n\n        // ==============================================\n\n        private bool LookupIsBrowsable()\n        {\n            Object attr = LookupCustomAttribute(typeof(EditorBrowsableAttribute));\n            if (null != attr)\n            {\n                EditorBrowsableAttribute eba = (EditorBrowsableAttribute)attr;\n                if (eba.State == EditorBrowsableState.Never)","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrProperty.cs#L289-L325","documentation":"ClrProperty.LookupCustomAttribute throws XamlSchemaException when more than one attribute of the requested type (attrType) is found on the property. The XAML schema model assumes attribute types used for single-value lookups are used at most once per property (AllowMultiple=false semantics). Multiple instances make the intended value ambiguous, so the schema refuses to guess.","triggerScenarios":"Calling attr()/LookupCustomAttribute (directly or via XamlType/XamlMember schema APIs) on a ClrProperty whose reflected CLR property has two or more attributes of the same type applied, e.g. two [XamlDeferLoad] or two duplicate custom metadata attributes on one property.","commonSituations":"Copy-pasting an attribute line twice on a property; a custom metadata attribute declared AllowMultiple=true that System.Xaml treats as single-use; assembly version merges duplicating attributes via MetadataUpdate or IL weaving/aspect-weaving tools re-applying attributes.","solutions":["Remove the duplicate attribute so only one instance of attrType remains on the property.","If multiple instances are intentional, stop relying on the single-attribute lookup API and read all instances with GetCustomAttributes yourself.","Mark the attribute type AllowMultiple=false and fix the declaration site flagged by the exception message (declaring type and property name are in the message)."],"exampleFix":"// before\n[XamlDeferLoad(\"A\", \"B\")]\n[XamlDeferLoad(\"C\", \"D\")]\npublic Foo Bar { get; set; }\n\n// after\n[XamlDeferLoad(\"A\", \"B\")]\npublic Foo Bar { get; set; }","handlingStrategy":"validation","validationCode":"// before schema use: assert single attribute per property\nvar attrs = prop.GetCustomAttributes(attrType, inherit: true).ToArray();\nif (attrs.Length > 1)\n    throw new InvalidOperationException($\"{prop.DeclaringType.Name}.{prop.Name} has {attrs.Length} {attrType.Name}; expected at most 1\");","typeGuard":"bool HasSingle<TAttr>(MemberInfo m) => m.GetCustomAttributes(typeof(TAttr), true).Length == 1;","tryCatchPattern":"try { var value = schemaProperty.Attr<TAttr>(); }\ncatch (XamlSchemaException ex) { log(ex.Message); /* fall back to manual attribute scan */ }","preventionTips":["Never apply the same schema attribute twice to a property","Keep AllowMultiple=false on attributes consumed by single-value lookups","Add a unit test that scans assemblies for duplicate schema attributes","Watch for IL weavers/mergers duplicating attributes in output assemblies"],"tags":["xaml","schema","duplicate-attribute"],"backgroundTag":"schema-validation-failed","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}