unoplatform/uno · error · ArgumentNullException

type

Error message

type

What it means

Thrown by the XamlTypeInvoker(XamlType type) constructor when `type` is null. The invoker must wrap a known XamlType to perform reflection; a null type leaves it with nothing to bind to. This guards against constructing an invoker in an invalid state.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeInvoker.cs:51

{
	[UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "Types manipulated here have been marked earlier")]
	[UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
	[UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Types manipulated here have been marked earlier")]
	public class XamlTypeInvoker
	{
		static readonly XamlTypeInvoker unknown = new XamlTypeInvoker ();
		public static XamlTypeInvoker UnknownInvoker {
			get { return unknown; }
		}

		protected XamlTypeInvoker ()
		{
		}
		
		public XamlTypeInvoker (XamlType type)
		{
			if (type == null)
				throw new ArgumentNullException ("type");
			this.type = type;
		}
		
		XamlType type;

		void ThrowIfUnknown ()
		{
			if (type == null || type.UnderlyingType == null)
				throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "Current operation is valid only when the underlying type on a XamlType is known, but it is unknown for '{0}'", type));
		}

		public EventHandler<XamlSetMarkupExtensionEventArgs> SetMarkupExtensionHandler {
			get { return type == null ? null : type.SetMarkupExtensionHandler; }
		}

		public EventHandler<XamlSetTypeConverterEventArgs> SetTypeConverterHandler {
			get { return type == null ? null : type.SetTypeConverterHandler; }
		}

View on GitHub (pinned to 0418340488)

Solutions

  1. Null-check the XamlType before constructing the invoker: `if (xamlType == null) throw/log;`.
  2. Use XamlType.Invoker property instead of `new XamlTypeInvoker(type)` — it handles the lookup correctly.
  3. Fix the upstream type resolution so GetXamlType returns a non-null XamlType (check assembly references and xmlns mappings).

Example fix

// before
var invoker = new XamlTypeInvoker(resolvedType); // resolvedType may be null

// after
var invoker = resolvedType != null ? resolvedType.Invoker : XamlTypeInvoker.UnknownInvoker;
Defensive patterns

Strategy: validation

Validate before calling

// before constructing
if (type == null) throw new InvalidOperationException("XamlType resolution returned null.");
var invoker = type.Invoker; // prefer the property over the constructor

Prevention

When it happens

Trigger: Constructing `new XamlTypeInvoker(null)` directly, or passing a XamlType that resolved to null from XamlSchemaContext.GetXamlType when type resolution failed.

Common situations: Custom XAML writers that build an invoker from a type lookup that silently returned null; type-resolution failures (missing assembly/namespace) where the null propagates into invoker construction.

Related errors


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