unoplatform/uno · error · ArgumentNullException
xmlns
Error message
xmlns
What it means
Thrown by XamlSchemaContext.GetPreferredPrefix when the xmlns argument is null. GetPreferredPrefix returns the preferred XML prefix for a namespace ('x' for Xaml2006, else a registered prefix or 'p'); a null namespace cannot be looked up, so it fails fast.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlSchemaContext.cs:197
all_xaml_types = new Dictionary<string, List<XamlType>>();
foreach (var ass in AssembliesInScope)
FillAllXamlTypes(ass);
}
List<XamlType> l;
if (all_xaml_types.TryGetValue(xamlNamespace, out l))
return l;
else
return empty_xaml_types;
}
}
public virtual string GetPreferredPrefix (string xmlns)
{
lock (gate)
{
if (xmlns == null)
throw new ArgumentNullException("xmlns");
if (xmlns == XamlLanguage.Xaml2006Namespace)
return "x";
if (prefixes == null)
{
prefixes = new Dictionary<string, string>();
foreach (var ass in AssembliesInScope)
FillPrefixes(ass);
}
string ret;
return prefixes.TryGetValue(xmlns, out ret) ? ret : "p"; // default
}
}
protected internal XamlValueConverter<TConverterBase> GetValueConverter<
[DynamicallyAccessedMembers(XamlValueConverter<TConverterBase>.TConverterBaseRequirements)] TConverterBase
> ([DynamicallyAccessedMembers(XamlValueConverter<TConverterBase>.TConverterBaseRequirements)] Type converterType, XamlType targetType)
where TConverterBase : class
{View on GitHub (pinned to 0418340488)
Solutions
- Pass a non-null namespace string to GetPreferredPrefix.
- Guard nullable namespaces at the call site before invoking the method.
- Default to XamlLanguage.Xaml2006Namespace when the intended namespace is the XAML language namespace.
Example fix
// before var prefix = ctx.GetPreferredPrefix(ns); // ns may be null // after var prefix = ns != null ? ctx.GetPreferredPrefix(ns) : "p";
Defensive patterns
Strategy: validation
Validate before calling
if (xmlns == null)
throw new InvalidOperationException("xmlns must be non-null before calling GetPreferredPrefix.");
var prefix = ctx.GetPreferredPrefix(xmlns); Prevention
- Guard nullable namespaces before calling GetPreferredPrefix.
- Default to a sensible prefix ('p') when the namespace is unknown rather than null.
- Centralize namespace handling so null never reaches the schema context.
When it happens
Trigger: Calling `schemaContext.GetPreferredPrefix(null)` — usually a caller that passed a namespace obtained from an unresolved declaration.
Common situations: Serialization/round-tripping code forwarding a nullable namespace; namespace lookups that returned null and were not guarded.
Related errors
- xamlNamespace
- xamlTypeName
- schemaContext
- The {0} string passed in the colorString argument is not a r
- The {0} string passed in the colorString argument is not a r
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/643c9cbf83a5c84a.
Report an issue: GitHub.