unoplatform/uno · error · ArgumentNullException
namespaceResolver
Error message
namespaceResolver
What it means
Thrown by XamlTypeName.TryParse when the `namespaceResolver` argument is null. The parser must resolve every prefix to a namespace via the resolver, so a null resolver makes type resolution impossible. It is rejected up front rather than failing later inside prefix lookup.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeName.cs:47
namespace Uno.Xaml.Schema
{
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Types manipulated here have been marked earlier")]
public class XamlTypeName
{
public static XamlTypeName Parse (string typeName, IXamlNamespaceResolver namespaceResolver)
{
XamlTypeName n;
if (!TryParse (typeName, namespaceResolver, out n))
throw new FormatException (String.Format (CultureInfo.InvariantCulture, "Invalid typeName: '{0}'", typeName));
return n;
}
public static bool TryParse (string typeName, IXamlNamespaceResolver namespaceResolver, out XamlTypeName result)
{
if (typeName == null)
throw new ArgumentNullException ("typeName");
if (namespaceResolver == null)
throw new ArgumentNullException ("namespaceResolver");
result = null;
IList<XamlTypeName> args = null;
int nArray = 0;
int idx;
if (typeName.Length > 2 && typeName [typeName.Length - 1] == ']') {
idx = typeName.LastIndexOf ('[');
if (idx < 0)
return false; // mismatch brace
nArray = 1;
for (int i = idx + 1; i < typeName.Length - 1; i++) {
if (typeName [i] != ',')
return false; // only ',' is expected
nArray++;
}
if (!TryParse (typeName.Substring (0, idx), namespaceResolver, out result))
return false;View on GitHub (pinned to 0418340488)
Solutions
- Construct and pass a valid IXamlNamespaceResolver (e.g. from a XamlXmlReader's namespace table or a custom implementation) before parsing.
- If no namespace resolution is needed, build a trivial resolver that maps the empty prefix to your default namespace.
- Null-check before calling and fail fast with your own context-rich error.
Example fix
// before
XamlTypeName.TryParse(typeName, null, out var name);
// after
var resolver = new NamespaceTableLookup(); // implements IXamlNamespaceResolver
resolver.Register("", "http://schemas.example.com/default");
XamlTypeName.TryParse(typeName, resolver, out var name); Defensive patterns
Strategy: validation
Validate before calling
// before TryParse
if (namespaceResolver == null) throw new InvalidOperationException("A namespace resolver is required to parse XAML type names."); Prevention
- Always construct an IXamlNamespaceResolver (or reuse a reader's) before parsing.
- Build a trivial resolver mapping the empty prefix to your default namespace if nothing else.
When it happens
Trigger: Calling XamlTypeName.TryParse(typeName, null, out _); passing null where an IXamlNamespaceResolver is expected because the caller had no namespace context available.
Common situations: Ad-hoc parsing calls outside a XAML reader where no namespace resolver was constructed; refactors that dropped the resolver argument; tests that passed null and expected graceful handling.
Related errors
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/4100395464a72b12.
Report an issue: GitHub.