unoplatform/uno · error · ArgumentNullException

typeArguments array contains one or more null XamlTypeName

Error message

typeArguments array contains one or more null XamlTypeName

What it means

Thrown by the XamlTypeName(string,string,IEnumerable<XamlTypeName>) constructor when the supplied typeArguments collection contains at least one null element. XamlTypeName models a fully-qualified XAML type with optional generic type arguments; a null entry in that list would produce malformed type strings and corrupt the XAML node stream, so the constructor rejects it eagerly.

Solutions

  1. Filter nulls out of the typeArguments collection before passing it: typeArguments.Where(t => t != null).
  2. Fix the upstream code that produces null XamlTypeName entries (e.g. a mapping dictionary lookup returning null) rather than just filtering downstream.
  3. Pass null as typeArguments when you have no generic parameters, instead of an empty or partially-null list.

Example fix

// before
var args = types.Select(t => MapOrNull(t));
var name = new XamlTypeName(ns, typeName, args);

// after
var args = types.Select(t => MapOrNull(t)).Where(t => t != null);
var name = new XamlTypeName(ns, typeName, args);
Defensive patterns

Strategy: validation

Validate before calling

var filtered = typeArguments?.Where(t => t != null).ToList();
var name = new XamlTypeName(xamlNamespace, nameStr, filtered);

Type guard

static IEnumerable<XamlTypeName> SafeArgs(IEnumerable<XamlTypeName> args)
    => args?.Where(t => t != null) ?? Enumerable.Empty<XamlTypeName>();

Try / catch

try { var tn = new XamlTypeName(ns, n, args); }
catch (ArgumentNullException ex) when (ex.ParamName == "typeArguments")
{ /* log and filter nulls, retry */ }

Prevention

When it happens

Trigger: Constructing an XamlTypeName with a non-null typeArguments enumerable that itself contains a null entry, e.g. new XamlTypeName("ns","List", new XamlTypeName[]{ null }). Also fires when a LINQ Select producing type arguments yields null for any element (e.g. mapping an unresolved type).

Common situations: Programmatic XAML schema construction where generic type arguments are resolved from metadata at runtime and some resolution returns null. Copying a type-argument list from a partially-populated dictionary. Reflection-driven XAML generation where a reflected generic parameter could not be mapped to an XAML namespace.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/463a5d7229297446. Report an issue: GitHub.

Appendix: source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeName.cs:222

				var l = new List<XamlTypeName> ();
				l.AddRange (xamlType.TypeArguments.Select (x => new XamlTypeName (x)));
				TypeArguments = l;
			}
		}
		
		public XamlTypeName (string xamlNamespace, string name)
			: this (xamlNamespace, name, null)
		{
		}

		public XamlTypeName (string xamlNamespace, string name, IEnumerable<XamlTypeName> typeArguments)
			: this ()
		{
			Namespace = xamlNamespace;
			Name = name;
			if (typeArguments != null) {
				if (typeArguments.Any (t => t == null))
					throw new ArgumentNullException ("typeArguments", "typeArguments array contains one or more null XamlTypeName");
				var l = new List<XamlTypeName> ();
				l.AddRange (typeArguments);
				TypeArguments = l;
			}
		}

		public string Name { get; set; }
		public string Namespace { get; set; }
		public IList<XamlTypeName> TypeArguments { get; private set; }

		public override string ToString ()
		{
			return ToString (null);
		}

		public string ToString (INamespacePrefixLookup prefixLookup)
		{
			if (Namespace == null)

View on GitHub (pinned to 0418340488)