unoplatform/uno · error · ArgumentNullException

schemaContext

Error message

schemaContext

What it means

The XamlType(string unknownTypeNamespace, ...) constructor throws ArgumentNullException('schemaContext') when the XamlSchemaContext is null. The schema context owns type/member resolution and is stored on the XamlType; every XamlType requires one, and downstream calls (GetXamlType on generic arguments) would NRE without it.

Source

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

				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)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			SchemaContext = schemaContext;

View on GitHub (pinned to 0418340488)

Solutions

  1. Construct or obtain a XamlSchemaContext (e.g. new XamlSchemaContext()) before building any XamlType.
  2. Inject the schema context as a required constructor dependency and fail fast in your factory if it is missing.
  3. Reuse a single cached XamlSchemaContext across all XamlType instances for a parse session to keep resolution consistent.

Example fix

// before
var xt = new XamlType(ns, name, typeArgs, null);

// after
var sctx = new XamlSchemaContext();
var xt = new XamlType(ns, name, typeArgs, sctx);
Defensive patterns

Strategy: validation

Validate before calling

if (schemaContext == null) schemaContext = new XamlSchemaContext();
var xt = new XamlType(unknownTypeNamespace, unknownTypeName, typeArguments, schemaContext);

Prevention

When it happens

Trigger: Constructing a XamlType without a schema context — typically when a caller built the context lazily and it was null, or in tests that omitted the dependency.

Common situations: Dependency-injection misconfiguration where the schema context was not provided; refactoring that removed context creation; shared static context not yet initialized at construction time.

Related errors


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