unoplatform/uno · error · ObjectDisposedException
reader
Error message
reader
What it means
Thrown by XamlObjectReader.Read as an ObjectDisposedException (object name 'reader') when IsDisposed is true. This indicates the reader was disposed (via Close/Dispose) and Read() was called afterward — the underlying node stream is gone and reading is no longer valid.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectReader.cs:175
get { return sctx; }
}
public override XamlType Type {
get { return NodeType == XamlNodeType.StartObject ? nodes.Current.Object.Type : null; }
}
public override object Value {
get {
if (NodeType != XamlNodeType.Value)
return null;
return nodes.Current.Value;
}
}
public override bool Read ()
{
if (IsDisposed)
throw new ObjectDisposedException ("reader");
if (IsEof)
return false;
if (ns_iterator == null)
ns_iterator = PrefixLookup.Namespaces.GetEnumerator ();
if (ns_iterator.MoveNext ())
return true;
if (nodes == null)
nodes = new XamlObjectNodeIterator (root, sctx, value_serializer_context).GetNodes ().GetEnumerator ();
if (nodes.MoveNext ())
return true;
if (!is_eof)
is_eof = true;
return false;
}
}
}
View on GitHub (pinned to 0418340488)
Solutions
- Do not call Read() after the reader is disposed — scope all reads within the using block.
- Track disposal state in your pipeline and skip or recreate the reader for subsequent passes.
- Create a fresh XamlObjectReader for each read pass rather than reusing a disposed one.
Example fix
// before
using (var reader = new XamlObjectReader(obj, sctx))
{
while (reader.Read()) Process(reader);
} // disposed here
reader.Read(); // throws ObjectDisposedException
// after
using (var reader = new XamlObjectReader(obj, sctx))
{
while (reader.Read()) Process(reader);
}
// if you need to read again, create a new reader
using (var reader2 = new XamlObjectReader(obj, sctx))
{
while (reader2.Read()) Process(reader2);
} Defensive patterns
Strategy: validation
Validate before calling
if (reader.IsDisposed) throw new ObjectDisposedException("reader was disposed");
reader.Read(); Try / catch
try { reader.Read(); }
catch (ObjectDisposedException) { /* recreate reader */ } Prevention
- Scope all Read() calls within the using block that owns the reader.
- Do not hold stale reader references across disposal boundaries.
- Create a new reader per read pass.
When it happens
Trigger: Calling Read() after Close() or Dispose() on the same XamlObjectReader instance. Or holding a stale reader reference in a reused pipeline and calling Read in a second pass.
Common situations: XAML processing loops that use using(var reader = ...) blocks but then attempt to read outside the block. Reader pooling/reuse that calls Read after a prior consumer disposed the reader. Error-recovery paths that dispose on failure but continue iterating.
Related errors
- There is already an object of type {0} named as '{1}'. Objec
- schemaContext
- instance type '{0}' must be public and non-nested.
- instance type '{0}' has no default constructor.
- typeArguments array contains one or more null XamlTypeName
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/b9adc3766255bb1c.
Report an issue: GitHub.