dotnet/wpf · error · ArgumentException
SR.ParserAttributeArgsHigh with 'XmlnsDefinitionAttribute'…
Error message
SR.ParserAttributeArgsHigh with 'XmlnsDefinitionAttribute' (too many constructor arguments for XmlnsDefinitionAttribute)
What it means
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.
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
Example fix
// before
[assembly: XmlnsDefinition("http://mycompany.com/schema", "MyCompany.Controls", AssemblyName = "MyCompany.Controls")] // 3rd ctor arg
// after
[assembly: XmlnsDefinition("http://mycompany.com/schema", "MyCompany.Controls")] Defensive patterns
Strategy: validation
Validate before calling
foreach (var attr in asm.GetCustomAttributesData())
{
if (attr.AttributeType.Name == "XmlnsDefinitionAttribute" && attr.ConstructorArguments.Count > 2)
throw new InvalidOperationException($"{asm}: XmlnsDefinitionAttribute has too many ctor arguments");
} Try / catch
try { xmlnsCache.LoadClrnsToAssemblyNameMappingCache(asm); }
catch (ArgumentException ex) when (ex.Message.Contains("XmlnsDefinitionAttribute"))
{ log.Error("Referenced assembly has malformed XmlnsDefinitionAttribute", ex); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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…
- 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/5d81fe843f3cfb22.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsCache.cs:245
}
private void GetNamespacesFromDefinitionAttr(CustomAttributeData data, out string xmlns, out string clrns)
{
// typedConstructorArguments (the Attribute constructor arguments)
// [MyAttribute("test", Name=Hello)]
// "test" is the Constructor Argument
xmlns = null;
clrns = null;
IList<CustomAttributeTypedArgument> constructorArguments = data.ConstructorArguments;
for (int i = 0; i<constructorArguments.Count; i++)
{
CustomAttributeTypedArgument tca = constructorArguments[i];
if (i == 0)
xmlns = tca.Value as String;
else if (i == 1)
clrns = tca.Value as String;
else
throw new ArgumentException(SR.Format(SR.ParserAttributeArgsHigh, "XmlnsDefinitionAttribute"));
}
}
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;View on GitHub (pinned to 81131a70a4)