{"record":{"id":"5d81fe843f3cfb22","repo":"dotnet/wpf","slug":"sr-parserattributeargshigh-with-xmlnsdefinitionattribute-too","errorCode":null,"errorMessage":"SR.ParserAttributeArgsHigh with 'XmlnsDefinitionAttribute' (too many constructor arguments for XmlnsDefinitionAttribute)","messagePattern":"SR\\.ParserAttributeArgsHigh with 'XmlnsDefinitionAttribute' \\(too many constructor arguments for XmlnsDefinitionAttribute\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsCache.cs","lineNumber":245,"sourceCode":"        }\n\n        private void GetNamespacesFromDefinitionAttr(CustomAttributeData data, out string xmlns, out string clrns)\n        {\n            // typedConstructorArguments (the Attribute constructor arguments)\n            // [MyAttribute(\"test\", Name=Hello)]\n            // \"test\" is the Constructor Argument\n            xmlns = null;\n            clrns = 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                    xmlns = tca.Value as String;\n                else if (i == 1)\n                    clrns = tca.Value as String;\n                else\n                    throw new ArgumentException(SR.Format(SR.ParserAttributeArgsHigh, \"XmlnsDefinitionAttribute\"));\n            }\n        }\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;","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsCache.cs#L227-L263","documentation":"In XmlnsCache, GetNamespacesFromDefinitionAttr reads the constructor arguments of an [XmlnsDefinitionAttribute]. If more than two positional arguments are present, the code throws ArgumentException with ParserAttributeArgsHigh — the attribute is only defined with (xmlNamespace, clrNamespace) and WPF's parser cannot interpret extra arguments.","triggerScenarios":"An assembly referenced by the app declares [XmlnsDefinition] with a constructor having 3+ arguments (e.g. a custom or extended XmlnsDefinitionAttribute overload), and XmlnsCache scans the assembly via LoadClrnsToAssemblyNameMappingCache or GetClrnsToAssemblyNameMappingList.","commonSituations":"Using a redefined/extended XmlnsDefinitionAttribute with an extra parameter (e.g. assembly name or visibility hint); assembly referencing a different WPF version's attribute; hand-rolled attributes shadowing System.Windows.Markup.XmlnsDefinitionAttribute.","solutions":["Remove extra constructor arguments from the XmlnsDefinitionAttribute usage, keeping only xmlns and clrNamespace","Ensure the attribute used is System.Windows.Markup.XmlnsDefinitionAttribute, not a custom type with the same name","Check referenced assemblies for third-party extended attributes and split the metadata into separate attributes"],"exampleFix":"// before\n[assembly: XmlnsDefinition(\"http://mycompany.com/schema\", \"MyCompany.Controls\", AssemblyName = \"MyCompany.Controls\")] // 3rd ctor arg\n// after\n[assembly: XmlnsDefinition(\"http://mycompany.com/schema\", \"MyCompany.Controls\")]","handlingStrategy":"validation","validationCode":"foreach (var attr in asm.GetCustomAttributesData())\n{\n    if (attr.AttributeType.Name == \"XmlnsDefinitionAttribute\" && attr.ConstructorArguments.Count > 2)\n        throw new InvalidOperationException($\"{asm}: XmlnsDefinitionAttribute has too many ctor arguments\");\n}","typeGuard":null,"tryCatchPattern":"try { xmlnsCache.LoadClrnsToAssemblyNameMappingCache(asm); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"XmlnsDefinitionAttribute\"))\n{ log.Error(\"Referenced assembly has malformed XmlnsDefinitionAttribute\", ex); }","preventionTips":["Only use the two-argument System.Windows.Markup.XmlnsDefinitionAttribute constructor","Do not define custom attributes named XmlnsDefinitionAttribute","Audit referenced assemblies' assembly-level attributes after upgrades"],"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"}