{"record":{"id":"4c4be503ad1bd7e4","repo":"dotnet/wpf","slug":"sr-format-sr-toomanyattributesontype-reflectedtype-name","errorCode":null,"errorMessage":"SR.Format(SR.TooManyAttributesOnType, reflectedType.Name, attrType.Name)","messagePattern":"SR\\.Format\\(SR\\.TooManyAttributesOnType, reflectedType\\.Name, attrType\\.Name\\)","errorType":"exception","errorClass":"XamlSchemaException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs","lineNumber":1098,"sourceCode":"        // Used by Reflector for attribute lookups\n        protected override MemberInfo Member\n        {\n            get { return UnderlyingType; }\n        }\n\n        private static object GetCustomAttribute(Type attrType, Type reflectedType)\n        {\n            object[] objs = reflectedType.GetCustomAttributes(attrType, true);\n            if (objs.Length == 0)\n            {\n                return null;\n            }\n\n            if (objs.Length > 1)\n            {\n                string message = SR.Format(SR.TooManyAttributesOnType,\n                                                    reflectedType.Name, attrType.Name);\n                throw new XamlSchemaException(message);\n            }\n\n            return objs[0];\n        }\n\n        private static TypeVisibility GetVisibility(Type type)\n        {\n            bool nestedTypeIsInternal = false;\n            // If the type is nested, we need to check its entire declaring hierarchy\n            while (type.IsNested)\n            {\n                if (type.IsNestedAssembly || type.IsNestedFamORAssem)\n                {\n                    nestedTypeIsInternal = true;\n                }\n                else if (!type.IsNestedPublic)\n                {\n                    // Not public or internal","sourceCodeStart":1080,"sourceCodeEnd":1116,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs#L1080-L1116","documentation":"TypeReflector's public single-attribute lookup throws XamlSchemaException when more than one attribute of the requested type (attrType) is applied to the reflected type. Type-level schema attributes are expected to appear at most once; multiple instances make the value ambiguous.","triggerScenarios":"Calling the public TypeReflector method that fetches one attribute of attrType on a type carrying two or more instances of that attribute, e.g. two [XmlnsDefinition] or duplicate custom type-level metadata attributes.","commonSituations":"Duplicate attribute lines left by copy-paste on a class; an attribute marked AllowMultiple=true that the schema layer reads as single; assembly post-processing (weaving, merging) re-applying attributes.","solutions":["Remove the duplicate attribute from the type named in the exception message.","Enumerate all attribute instances with GetCustomAttributes instead of the single-attribute API when multiple are intentional.","Ensure build/merge tooling is not duplicating attribute declarations."],"exampleFix":"// before\n[ContentProperty(\"Items\")]\n[ContentProperty(\"Children\")]\nclass Panel { }\n\n// after\n[ContentProperty(\"Items\")]\nclass Panel { }","handlingStrategy":"validation","validationCode":"// assert at most one attrType per type before schema lookup\nvar count = type.GetCustomAttributes(attrType, inherit: true).Length;\nif (count > 1) throw new InvalidOperationException($\"{type.Name} has {count} {attrType.Name}; expected at most 1\");","typeGuard":"bool TypeHasSingle<TAttr>(Type t) => t.GetCustomAttributes(typeof(TAttr), true).Length == 1;","tryCatchPattern":"try { var a = typeReflector.GetCustomAttribute(attrType); }\ncatch (XamlSchemaException ex) { log(ex.Message); /* deduplicate the attribute on the type */ }","preventionTips":["Never duplicate type-level schema attributes like ContentProperty","Scan assemblies in tests for duplicate metadata attributes","Disable attribute duplication in ILMerge/weaver pipelines","Keep AllowMultiple=false for single-lookup attribute types"],"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"}