dotnet/wpf · error · ArgumentException
SR.ParserAttributeArgsHigh with…
Error message
SR.ParserAttributeArgsHigh with 'XmlnsCompatibleWithAttribute' (too many constructor arguments for XmlnsCompatibleWithAttribute)
What it means
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.
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
Example fix
// before
[assembly: XmlnsCompatibleWith("http://old/ns", "http://new/ns", "extraArg")]
// after
[assembly: XmlnsCompatibleWith("http://old/ns", "http://new/ns")] Defensive patterns
Strategy: validation
Validate before calling
foreach (var attr in asm.GetCustomAttributesData())
{
if (attr.AttributeType.Name == "XmlnsCompatibleWithAttribute" && attr.ConstructorArguments.Count != 2)
throw new InvalidOperationException($"{asm}: XmlnsCompatibleWithAttribute must take exactly 2 arguments");
} Try / catch
try { ProcessXmlnsCompatibleWithAttributes(asm); }
catch (ArgumentException ex) when (ex.Message.Contains("XmlnsCompatibleWithAttribute"))
{ log.Error("Malformed XmlnsCompatibleWithAttribute", ex); } Prevention
- Always call XmlnsCompatibleWithAttribute with exactly (oldNamespace, newNamespace)
- Avoid attribute variants with extra parameters in referenced assemblies
- Review attribute metadata after assembly merges or rewrites
When it happens
Trigger: An assembly declares [XmlnsCompatibleWith] with three or more constructor arguments and ProcessXmlnsCompatibleWithAttributes scans the assembly's custom attributes.
Common situations: Custom/extended XmlnsCompatibleWithAttribute with additional parameters; mismatched attribute definitions between assemblies; metadata-rewriting tools appending arguments.
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
- SR.ParserAttributeArgsHigh with 'XmlnsDefinitionAttribute'…
- ArgumentNullException(nameof(clrNamespace))
- ArgumentNullException(nameof(contentType))
- ArgumentNullException(nameof(loaderType))
- ArgumentNullException(nameof(newNamespace))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/73c1f9ddefe1d191.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsCache.cs:265
}
private void GetNamespacesFromCompatAttr(CustomAttributeData data, out string oldXmlns, out string newXmlns)
{
// typedConstructorArguments (the Attribute constructor arguments)
// [MyAttribute("test", Name=Hello)]
// "test" is the Constructor Argument
oldXmlns = null;
newXmlns = null;
IList<CustomAttributeTypedArgument> constructorArguments = data.ConstructorArguments;
for (int i=0; i<constructorArguments.Count; i++)
{
CustomAttributeTypedArgument tca = constructorArguments[i];
if (i == 0)
oldXmlns = tca.Value as String;
else if (i == 1)
newXmlns = tca.Value as String;
else
throw new ArgumentException(SR.Format(SR.ParserAttributeArgsHigh, "XmlnsCompatibleWithAttribute"));
}
}
#else
private Attribute[] GetAttributes(Assembly asm, Type attrType)
{
return Attribute.GetCustomAttributes(asm, attrType);
}
private void GetNamespacesFromDefinitionAttr(Attribute attr, out string xmlns, out string clrns)
{
XmlnsDefinitionAttribute xmlnsAttr = (XmlnsDefinitionAttribute)attr;
xmlns = xmlnsAttr.XmlNamespace;
clrns = xmlnsAttr.ClrNamespace;
}
private void GetNamespacesFromCompatAttr(Attribute attr, out string oldXmlns, out string newXmlns)View on GitHub (pinned to 81131a70a4)