dotnet/wpf · error · ArgumentException
SR.ReferenceIsNull
Error message
SR.ReferenceIsNull
What it means
XamlSchemaContext.GetXamlType(XamlTypeName) validates that the type name's Name property is non-null before resolving. A XamlTypeName with a null Name cannot denote a type, so an ArgumentException naming the offending member is thrown.
Solutions
- Ensure XamlTypeName is constructed with a non-null local name
- Validate xamlTypeName.Name before calling GetXamlType
- Use XamlTypeName.Parse with a well-formed 'prefix:localName' string
Example fix
// before
var xn = new XamlTypeName("http://schemas.microsoft.com/winfx/2006/xaml", null);
schemaContext.GetXamlType(xn);
// after
var xn = new XamlTypeName("http://schemas.microsoft.com/winfx/2006/xaml", "NullExtension");
schemaContext.GetXamlType(xn); Defensive patterns
Strategy: validation
Validate before calling
if (xamlTypeName is null || xamlTypeName.Name is null) throw new ArgumentException("xamlTypeName must have a Name"); Type guard
bool HasName(XamlTypeName t) => t?.Name is not null;
Try / catch
try { var xt = ctx.GetXamlType(xtn); } catch (ArgumentException ex) when (ex.ParamName == "xamlTypeName") { /* handle missing Name */ } Prevention
- Always construct XamlTypeName with both namespace and local name
- Validate parsed names before resolving
When it happens
Trigger: Calling schemaContext.GetXamlType(new XamlTypeName(ns, null)) or passing a XamlTypeName constructed/parsed such that Name is null (e.g. default-constructed then partially filled).
Common situations: Manually building XamlTypeName instances; parsing prefix strings where the local-name portion was empty; refactoring code that previously supplied both namespace and name.
Related errors
- ArgumentNullException(nameof(assemblyName))
- ArgumentNullException(nameof(assemblyNames))
- ArgumentNullException(nameof(assemblyPath))
- ArgumentNullException(nameof(clrNamespace))
- ArgumentNullException(nameof(localName))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/6511a40e6e482ba9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs:279
if (XamlLanguage.XamlNamespaces.Contains(xamlNamespace))
{
return XamlLanguage.LookupXamlDirective(name);
}
else if (XamlLanguage.XmlNamespaces.Contains(xamlNamespace))
{
return XamlLanguage.LookupXmlDirective(name);
}
return null;
}
public XamlType GetXamlType(XamlTypeName xamlTypeName)
{
ArgumentNullException.ThrowIfNull(xamlTypeName);
if (xamlTypeName.Name is null)
{
throw new ArgumentException(SR.Format(SR.ReferenceIsNull, "xamlTypeName.Name"), nameof(xamlTypeName));
}
if (xamlTypeName.Namespace is null)
{
throw new ArgumentException(SR.Format(SR.ReferenceIsNull, "xamlTypeName.Namespace"), nameof(xamlTypeName));
}
XamlType[] typeArgs = null;
if (xamlTypeName.HasTypeArgs)
{
typeArgs = new XamlType[xamlTypeName.TypeArguments.Count];
for (int i = 0; i < xamlTypeName.TypeArguments.Count; i++)
{
if (xamlTypeName.TypeArguments[i] is null)
{
throw new ArgumentException(SR.Format(SR.CollectionCannotContainNulls, "xamlTypeName.TypeArguments"));
}
View on GitHub (pinned to 81131a70a4)