unoplatform/uno · error · ArgumentNullException

schemaContext

Error message

schemaContext

What it means

Thrown by the XamlObjectWriter constructor when the supplied XamlSchemaContext is null. The schema context is the writer's only way to resolve XAML types, members, namespaces, and type converters, so it is mandatory. A null value makes every subsequent write operation undefined, so the constructor fails fast.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs:82

*/

#if DOTNET
namespace Mono.Xaml
#else
namespace Uno.Xaml
#endif
{
	public class XamlObjectWriter : XamlWriter, IXamlLineInfoConsumer
	{
		public XamlObjectWriter (XamlSchemaContext schemaContext)
			: this (schemaContext, null)
		{
		}

		public XamlObjectWriter (XamlSchemaContext schemaContext, XamlObjectWriterSettings settings)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			this.sctx = schemaContext;
			this.settings = settings ?? new XamlObjectWriterSettings ();
			var manager = new XamlWriterStateManager<XamlObjectWriterException, XamlObjectWriterException> (false);
			intl = new XamlObjectWriterInternal (this, sctx, manager);
		}

		XamlSchemaContext sctx;
		XamlObjectWriterSettings settings;

		XamlObjectWriterInternal intl;

		//int line, column;
		bool lineinfo_was_given;

		internal XamlObjectWriterSettings Settings {
			get { return settings; }
		}

View on GitHub (pinned to 0418340488)

Solutions

  1. Pass a valid XamlSchemaContext, e.g. `new XamlSchemaContext()` or one built from the relevant assemblies: `new XamlSchemaContext(myAssemblies)`.
  2. If constructing in a factory, null-check the incoming dependency and supply a default context before calling the constructor.
  3. Register XamlSchemaContext in your DI container so it is never null at the call site.

Example fix

// before
var writer = new XamlObjectWriter(null);
// after
var writer = new XamlObjectWriter(new XamlSchemaContext());
Defensive patterns

Strategy: validation

Validate before calling

if (schemaContext == null)
    throw new InvalidOperationException("A XamlSchemaContext must be provided before constructing the writer.");
var writer = new XamlObjectWriter(schemaContext);

Prevention

When it happens

Trigger: Calling `new XamlObjectWriter(null)` or `new XamlObjectWriter(null, settings)`, i.e. invoking the constructor with a null first argument.

Common situations: DI/factory wiring that forgot to register or resolve a XamlSchemaContext; test scaffolding that passes null as a placeholder; refactoring that removed the context's creation but left the call site.

Related errors


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