unoplatform/uno · error · ArgumentNullException

unknownTypeNamespace

Error message

unknownTypeNamespace

What it means

The XamlType(string unknownTypeNamespace, string unknownTypeName, ...) constructor throws ArgumentNullException('unknownTypeNamespace') when the namespace argument is null. This overload represents a type that cannot be resolved at parse time (an 'unknown' XamlType), but it still requires a non-null namespace string to populate PreferredXamlNamespace.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlType.cs:87

			} else if ((xt = XamlLanguage.AllTypes.FirstOrDefault (t => t.UnderlyingType == type)) != null) {
				Name = xt.Name;
				PreferredXamlNamespace = XamlLanguage.Xaml2006Namespace;
			} else {
				Name = GetXamlName (type);
				PreferredXamlNamespace = schemaContext.GetXamlNamespace (type.Namespace) ?? String.Format (CultureInfo.InvariantCulture, "clr-namespace:{0};assembly={1}", type.Namespace, type.Assembly.GetName ().Name);
			}
			if (type.IsGenericType) {
				TypeArguments = new List<XamlType> ();
				foreach (var gta in type.GetGenericArguments ())
					TypeArguments.Add (schemaContext.GetXamlType (gta));
			}
		}

		public XamlType (string unknownTypeNamespace, string unknownTypeName, IList<XamlType> typeArguments, XamlSchemaContext schemaContext)
			: this (schemaContext, null)
		{
			if (unknownTypeNamespace == null)
				throw new ArgumentNullException ("unknownTypeNamespace");
			if (unknownTypeName == null)
				throw new ArgumentNullException ("unknownTypeName");
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");

			type = typeof (object);
			Name = unknownTypeName;
			PreferredXamlNamespace = unknownTypeNamespace;
			TypeArguments = typeArguments != null && typeArguments.Count == 0 ? null : typeArguments;
//			explicit_ns = unknownTypeNamespace;
		}

		protected XamlType (string typeName, IList<XamlType> typeArguments, XamlSchemaContext schemaContext)
			: this (String.Empty, typeName, typeArguments, schemaContext)
		{
		}

		XamlType (XamlSchemaContext schemaContext, XamlTypeInvoker invoker)

View on GitHub (pinned to 0418340488)

Solutions

  1. Pass a non-null namespace string (use string.Empty if the type has no explicit namespace, matching the protected XamlType overload).
  2. Validate the namespace is non-null at the source that produces it before constructing the unknown XamlType.
  3. If the namespace is genuinely unavailable, surface a parse error to the user rather than constructing an unknown type with null.

Example fix

// before
var xt = new XamlType(null, typeName, typeArgs, sctx);

// after
var xt = new XamlType(namespace ?? string.Empty, typeName, typeArgs, sctx);
Defensive patterns

Strategy: validation

Validate before calling

var ns = unknownTypeNamespace ?? string.Empty;
var xt = new XamlType(ns, unknownTypeName, typeArguments, schemaContext);

Prevention

When it happens

Trigger: Building an unknown XamlType for a forward-declared type whose XML namespace was not supplied, or passing a namespace variable that resolved to null during XAML parsing.

Common situations: XAML parsers constructing placeholder types for unresolved xmlns; tooling that synthesizes XamlType instances from incomplete metadata; tests omitting the namespace argument.

Related errors


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