{"record":{"id":"922ae1510565e53a","repo":"dotnet/wpf","slug":"sr-parserattributeargshigh","errorCode":null,"errorMessage":"SR.ParserAttributeArgsHigh","messagePattern":"SR\\.ParserAttributeArgsHigh","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs","lineNumber":365,"sourceCode":"                        throw new ArgumentException(SR.Format(SR.ParserAttributeArgsLow, attrType.Name));\n                    }\n                }\n                else if (constructorArguments.Count == 0)\n                {\n                    // zeroArgsAllowed = true for CPA for example.\n                    // CPA with no args is valid and would mean that this type is overriding a base CPA\n                    if (noArgs || zeroArgsAllowed)\n                    {\n                        attrValue = string.Empty;\n                    }\n                    else\n                    {\n                        throw new ArgumentException(SR.Format(SR.ParserAttributeArgsLow, attrType.Name));\n                    }\n                }\n                else\n                {\n                    throw new ArgumentException(SR.Format(SR.ParserAttributeArgsHigh, attrType.Name));\n                }\n            }\n\n            return attrValue;\n        }\n\n#endregion Attributes\n\n#region Assembly Loading\n\n#if !PBTCOMPILER\n        //\n        // Clean up the cache entry for the given assembly, so that it can be reloaded.\n         //\n        internal static void ResetCacheForAssembly(string assemblyName)\n        {\n            string assemblyNameLookup = assemblyName.ToUpper(CultureInfo.InvariantCulture);\n            _loadedAssembliesHash[assemblyNameLookup] = null;","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs#L347-L383","documentation":"ReflectionHelper.GetCustomAttributeData only supports attributes with zero or one constructor arguments. When the scanned CustomAttributeData has more than one constructor argument, it throws ArgumentException('SR.ParserAttributeArgsHigh') naming the attribute type. The helper deliberately rejects multi-argument attribute usages because it can only decode a single string (or Type) value.","triggerScenarios":"A type in the scanned assembly carries an attribute instance constructed with two or more constructor arguments (constructorArguments.Count > 1) while ReflectionHelper walks the type hierarchy via CustomAttributeData.GetCustomAttributes in ReflectionHelper.cs:363-366.","commonSituations":"Applying an attribute like [Attribute(\"a\", \"b\")] or [Attribute(1, Name=\"x\")] where the markup tooling expects only [Attribute(\"single-string\")]; third-party or newly added attributes with multiple positional parameters appearing on types scanned by the XAML markup compiler.","solutions":["Reduce the attribute usage to a single string (or typeof(Type)) constructor argument.","Move complex metadata into named properties/elements the parser understands, or into a different attribute designed for multi-value data.","Check the attribute type named in the message and remove or re-author its multi-argument usage on the scanned type hierarchy.","If you control the attribute class, add a single-string constructor overload and use it."],"exampleFix":"// before\n[MyAttribute(\"value1\", \"value2\")]\nclass Foo { }\n\n// after\n[MyAttribute(\"value1\")]\nclass Foo { }","handlingStrategy":"validation","validationCode":"// Reject multi-argument attribute usages before the parser does\nforeach (var cad in CustomAttributeData.GetCustomAttributes(type))\n    if (cad.Constructor.ReflectedType == typeof(MyAttribute) &&\n        cad.ConstructorArguments.Count > 1)\n        throw new InvalidOperationException($\"{nameof(MyAttribute)} takes at most one constructor argument\");","typeGuard":"static bool HasAtMostOneArg(CustomAttributeData cad) =>\n    cad.ConstructorArguments.Count <= 1;","tryCatchPattern":"try\n{\n    ScanAttributes(type);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"ParserAttributeArgs\"))\n{\n    // attribute has too many ctor arguments — reduce to one string/Type\n}","preventionTips":["Keep markup-scanned attributes limited to a single string or typeof(Type) constructor argument.","Encode extra metadata in named properties or separate attributes instead of extra positional args.","Lint attribute usages in CI with CustomAttributeData reflection checks."],"tags":["wpf","markup","reflection","attributes","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-22T01:17:13.364Z"}