{"record":{"id":"73c1f9ddefe1d191","repo":"dotnet/wpf","slug":"sr-parserattributeargshigh-with-xmlnscompatiblewithattribute","errorCode":null,"errorMessage":"SR.ParserAttributeArgsHigh with 'XmlnsCompatibleWithAttribute' (too many constructor arguments for XmlnsCompatibleWithAttribute)","messagePattern":"SR\\.ParserAttributeArgsHigh with 'XmlnsCompatibleWithAttribute' \\(too many constructor arguments for XmlnsCompatibleWithAttribute\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsCache.cs","lineNumber":265,"sourceCode":"        }\n\n        private void GetNamespacesFromCompatAttr(CustomAttributeData data, out string oldXmlns, out string newXmlns)\n        {\n            // typedConstructorArguments (the Attribute constructor arguments)\n            // [MyAttribute(\"test\", Name=Hello)]\n            // \"test\" is the Constructor Argument\n            oldXmlns = null;\n            newXmlns = null;\n            IList<CustomAttributeTypedArgument> constructorArguments = data.ConstructorArguments;\n            for (int i=0; i<constructorArguments.Count; i++)\n            {\n                CustomAttributeTypedArgument tca = constructorArguments[i];\n                if (i == 0)\n                    oldXmlns = tca.Value as String;\n                else if (i == 1)\n                    newXmlns = tca.Value as String;\n                else\n                    throw new ArgumentException(SR.Format(SR.ParserAttributeArgsHigh, \"XmlnsCompatibleWithAttribute\"));\n            }\n        }\n\n#else\n\n        private Attribute[] GetAttributes(Assembly asm, Type attrType)\n        {\n            return Attribute.GetCustomAttributes(asm, attrType);\n        }\n\n        private void GetNamespacesFromDefinitionAttr(Attribute attr, out string xmlns, out string clrns)\n        {\n            XmlnsDefinitionAttribute xmlnsAttr  = (XmlnsDefinitionAttribute)attr;\n            xmlns = xmlnsAttr.XmlNamespace;\n            clrns = xmlnsAttr.ClrNamespace;\n        }\n\n        private void GetNamespacesFromCompatAttr(Attribute attr, out string oldXmlns, out string newXmlns)","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsCache.cs#L247-L283","documentation":"In XmlnsCache, GetNamespacesFromCompatAttr parses an [XmlnsCompatibleWithAttribute] constructor arguments (oldNamespace, newNamespace). If the attribute carries more than two arguments, an ArgumentException with ParserAttributeArgsHigh is thrown because WPF only supports the two-argument constructor.","triggerScenarios":"An assembly declares [XmlnsCompatibleWith] with three or more constructor arguments and ProcessXmlnsCompatibleWithAttributes scans the assembly's custom attributes.","commonSituations":"Custom/extended XmlnsCompatibleWithAttribute with additional parameters; mismatched attribute definitions between assemblies; metadata-rewriting tools appending arguments.","solutions":["Use exactly the two-argument constructor: (oldNamespace, newNamespace)","Remove any extra arguments or express them as named properties if the attribute type allows","Verify the referenced attribute type is the standard System.Windows.Markup.XmlnsCompatibleWithAttribute"],"exampleFix":"// before\n[assembly: XmlnsCompatibleWith(\"http://old/ns\", \"http://new/ns\", \"extraArg\")]\n// after\n[assembly: XmlnsCompatibleWith(\"http://old/ns\", \"http://new/ns\")]","handlingStrategy":"validation","validationCode":"foreach (var attr in asm.GetCustomAttributesData())\n{\n    if (attr.AttributeType.Name == \"XmlnsCompatibleWithAttribute\" && attr.ConstructorArguments.Count != 2)\n        throw new InvalidOperationException($\"{asm}: XmlnsCompatibleWithAttribute must take exactly 2 arguments\");\n}","typeGuard":null,"tryCatchPattern":"try { ProcessXmlnsCompatibleWithAttributes(asm); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"XmlnsCompatibleWithAttribute\"))\n{ log.Error(\"Malformed XmlnsCompatibleWithAttribute\", ex); }","preventionTips":["Always call XmlnsCompatibleWithAttribute with exactly (oldNamespace, newNamespace)","Avoid attribute variants with extra parameters in referenced assemblies","Review attribute metadata after assembly merges or rewrites"],"tags":["wpf","xaml","attribute","argument-count"],"backgroundTag":"invalid-argument-value","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"}