unoplatform/uno · error · ArgumentNullException
schemaContext
Error message
schemaContext
What it means
Thrown by the XamlObjectReader(object, XamlSchemaContext, XamlObjectReaderSettings) constructor when schemaContext is null. XamlObjectReader needs a schema context to resolve XamlType and XamlMember identity for the object graph it reads; a null context makes type resolution impossible and is rejected with ArgumentNullException.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectReader.cs:79
public XamlObjectReader (object instance)
: this (instance, new XamlSchemaContext (null, null), null)
{
}
public XamlObjectReader (object instance, XamlObjectReaderSettings settings)
: this (instance, new XamlSchemaContext (null, null), settings)
{
}
public XamlObjectReader (object instance, XamlSchemaContext schemaContext)
: this (instance, schemaContext, null)
{
}
public XamlObjectReader (object instance, XamlSchemaContext schemaContext, XamlObjectReaderSettings settings)
{
if (schemaContext == null)
throw new ArgumentNullException ("schemaContext");
// FIXME: special case? or can it be generalized? In .NET, For Type instance Instance returns TypeExtension at root StartObject, while for Array it remains to return Array.
if (instance is Type)
instance = new TypeExtension ((Type) instance);
// See also Instance property for this weirdness.
this.root_raw = instance;
instance = TypeExtensionMethods.GetExtensionWrapped (instance);
this.root = instance;
sctx = schemaContext;
// this.settings = settings;
// check type validity. Note that some checks also needs done at Read() phase. (it is likely FIXME:)
if (instance != null) {
var type = new InstanceContext (instance).GetRawValue ().GetType ();
if (!type.IsPublic)
throw new XamlObjectReaderException (String.Format (CultureInfo.InvariantCulture, "instance type '{0}' must be public and non-nested.", type));
var xt = SchemaContext.GetXamlType (type);View on GitHub (pinned to 0418340488)
Solutions
- Pass a valid XamlSchemaContext: new XamlObjectReader(obj, new XamlSchemaContext()).
- Reuse the schema context from a related reader/writer to maintain consistency.
- Guard: var sctx = providedSchemaContext ?? new XamlSchemaContext();
Example fix
// before var reader = new XamlObjectReader(myObject, schemaContext); // null // after var reader = new XamlObjectReader(myObject, schemaContext ?? new XamlSchemaContext());
Defensive patterns
Strategy: validation
Validate before calling
var ctx = schemaContext ?? new XamlSchemaContext(); var reader = new XamlObjectReader(obj, ctx);
Try / catch
try { var reader = new XamlObjectReader(obj, sctx); }
catch (ArgumentNullException) { var reader = new XamlObjectReader(obj, new XamlSchemaContext()); } Prevention
- Always pass a non-null XamlSchemaContext to XamlObjectReader.
- Reuse a context from related reader/writer for consistency.
When it happens
Trigger: Constructing new XamlObjectReader(obj, null) or new XamlObjectReader(obj, null, settings) — passing a null schema context. Typically from a variable that was conditionally assigned or from a factory returning null.
Common situations: XAML serialization entry points that accept an optional schema context and default it incorrectly to null. Code that constructs XamlObjectReader without reading the schema context from a parent reader/writer.
Related errors
- schemaContext
- typeArguments array contains one or more null XamlTypeName
- Either property getter or setter must be non-null.
- instance
- There is already an object of type {0} named as '{1}'. Objec
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/c81c4089854e61aa.
Report an issue: GitHub.