dotnet/wpf · error · ArgumentException

SR.ParserAttributeArgsHigh

Error message

SR.ParserAttributeArgsHigh

What it means

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.

Solutions

  1. Reduce the attribute usage to a single string (or typeof(Type)) constructor argument.
  2. Move complex metadata into named properties/elements the parser understands, or into a different attribute designed for multi-value data.
  3. Check the attribute type named in the message and remove or re-author its multi-argument usage on the scanned type hierarchy.
  4. If you control the attribute class, add a single-string constructor overload and use it.

Example fix

// before
[MyAttribute("value1", "value2")]
class Foo { }

// after
[MyAttribute("value1")]
class Foo { }
Defensive patterns

Strategy: validation

Validate before calling

// Reject multi-argument attribute usages before the parser does
foreach (var cad in CustomAttributeData.GetCustomAttributes(type))
    if (cad.Constructor.ReflectedType == typeof(MyAttribute) &&
        cad.ConstructorArguments.Count > 1)
        throw new InvalidOperationException($"{nameof(MyAttribute)} takes at most one constructor argument");

Type guard

static bool HasAtMostOneArg(CustomAttributeData cad) =>
    cad.ConstructorArguments.Count <= 1;

Try / catch

try
{
    ScanAttributes(type);
}
catch (ArgumentException ex) when (ex.Message.Contains("ParserAttributeArgs"))
{
    // attribute has too many ctor arguments — reduce to one string/Type
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/922ae1510565e53a. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs:365

                        throw new ArgumentException(SR.Format(SR.ParserAttributeArgsLow, attrType.Name));
                    }
                }
                else if (constructorArguments.Count == 0)
                {
                    // zeroArgsAllowed = true for CPA for example.
                    // CPA with no args is valid and would mean that this type is overriding a base CPA
                    if (noArgs || zeroArgsAllowed)
                    {
                        attrValue = string.Empty;
                    }
                    else
                    {
                        throw new ArgumentException(SR.Format(SR.ParserAttributeArgsLow, attrType.Name));
                    }
                }
                else
                {
                    throw new ArgumentException(SR.Format(SR.ParserAttributeArgsHigh, attrType.Name));
                }
            }

            return attrValue;
        }

#endregion Attributes

#region Assembly Loading

#if !PBTCOMPILER
        //
        // Clean up the cache entry for the given assembly, so that it can be reloaded.
         //
        internal static void ResetCacheForAssembly(string assemblyName)
        {
            string assemblyNameLookup = assemblyName.ToUpper(CultureInfo.InvariantCulture);
            _loadedAssembliesHash[assemblyNameLookup] = null;

View on GitHub (pinned to 81131a70a4)