unoplatform/uno · error · ArgumentNullException

prefixLookup

Error message

prefixLookup

What it means

Thrown by XamlTypeName.ToString(IList<XamlTypeName>, INamespacePrefixLookup) when the `prefixLookup` argument is null. When rendering each type name to its prefixed form, the method calls LookupPrefix on the resolver, so a null prefix lookup cannot produce prefixes; it is rejected up front.

Source

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

			}

			var ret = new List<XamlTypeName> ();
		 	foreach (var s in l) {
				if (!TryParse (s, namespaceResolver, out tn))
					return false;
				ret.Add (tn);
			}

			result = ret;
			return true;
		}

		public static string ToString (IList<XamlTypeName> typeNameList, INamespacePrefixLookup prefixLookup)
		{
			if (typeNameList == null)
				throw new ArgumentNullException ("typeNameList");
			if (prefixLookup == null)
				throw new ArgumentNullException ("prefixLookup");

			return DoToString (typeNameList, prefixLookup);
		}

		static string DoToString (IList<XamlTypeName> typeNameList, INamespacePrefixLookup prefixLookup)
		{
			bool comma = false;
			string ret = "";
			foreach (var ta in typeNameList) {
				if (comma)
					ret += ", ";
				else
					comma = true;
				ret += ta.ToString (prefixLookup);
			}
			return ret;
		}

View on GitHub (pinned to 0418340488)

Solutions

  1. Construct and pass a valid INamespacePrefixLookup (e.g. from a XamlXmlWriter's namespace table or a custom implementation) before formatting.
  2. If you only need the brace-namespace form (no prefix), call each XamlTypeName.ToString() (parameterless) and join manually.
  3. Null-check before calling and fail fast with context.

Example fix

// before
var s = XamlTypeName.ToString(list, null);

// after
// no prefix table available: render brace-namespace form instead
var s = string.Join(", ", list.Select(t => t.ToString()));
Defensive patterns

Strategy: validation

Validate before calling

// before ToString with prefixes
if (prefixLookup == null) {
    // fall back to brace-namespace form
    var s = string.Join(", ", typeNameList.Select(t => t.ToString()));
    return s;
}

Prevention

When it happens

Trigger: Calling XamlTypeName.ToString(list, null); rendering a list to prefixed form without supplying an INamespacePrefixLookup.

Common situations: Formatting type names outside a XAML writer where no prefix table exists; refactors dropping the lookup; assuming the method tolerates null.

Related errors


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