{"record":{"id":"1e4fa1cc6dddc9c4","repo":"unoplatform/uno","slug":"reader-1e4fa1","errorCode":null,"errorMessage":"reader","messagePattern":"reader","errorType":"exception","errorClass":"ObjectDisposedException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlXmlReader.cs","lineNumber":217,"sourceCode":"\t\t\tget { return iter != null ? iter.Current.NodeType : XamlNodeType.None; }\n\t\t}\n\n\t\tpublic override XamlSchemaContext SchemaContext {\n\t\t\tget { return parser.SchemaContext; }\n\t\t}\n\n\t\tpublic override XamlType Type {\n\t\t\tget { return iter != null && iter.Current.NodeType == XamlNodeType.StartObject ? (XamlType) iter.Current.NodeValue : null; }\n\t\t}\n\n\t\tpublic override object Value {\n\t\t\tget { return iter != null && iter.Current.NodeType == XamlNodeType.Value ? iter.Current.NodeValue : null; }\n\t\t}\n\n\t\tpublic override bool Read ()\n\t\t{\n\t\t\tif (IsDisposed)\n\t\t\t\tthrow new ObjectDisposedException (\"reader\");\n\t\t\tif (iter == null)\n\t\t\t\titer = parser.Parse ().GetEnumerator ();\n\t\t\titer.MoveNext ();\n\t\t\treturn iter.Current.NodeType != XamlNodeType.None;\n\t\t}\n\t}\n\n\tstruct XamlXmlNodeInfo\n\t{\n\t\tpublic XamlXmlNodeInfo (XamlNodeType nodeType, object nodeValue, IXmlLineInfo lineInfo)\n\t\t{\n\t\t\tNodeType = nodeType;\n\t\t\tNodeValue = nodeValue;\n\t\t\tif (lineInfo != null && lineInfo.HasLineInfo ()) {\n\t\t\t\tHasLineInfo = true;\n\t\t\t\tLineNumber = lineInfo.LineNumber;\n\t\t\t\tLinePosition = lineInfo.LinePosition;\n\t\t\t} else {","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlXmlReader.cs#L199-L235","documentation":"XamlXmlReader.Read throws ObjectDisposedException('reader') when Read is called after the reader was disposed (IsDisposed is true). The reader lazily initializes its node enumerator on first Read; once disposed, any further read attempt is rejected to prevent operating on released parser state.","triggerScenarios":"Calling Read after the XamlXmlReader (or its underlying XmlReader/stream) was disposed — e.g. a using block disposed the reader but a deferred iterator or background task still calls Read.","commonSituations":"Streaming/lazy evaluation where the reader is disposed before the consumer finishes iterating; 'using' scope mismatch with async enumeration; code that caches a reader across disposal boundaries; reusing a reader after XamlServices.Transform closed resources.","solutions":["Ensure the consumer finishes reading before the reader is disposed (move the using scope to wrap the entire consumption loop).","Do not reuse a XamlXmlReader after disposal — create a fresh one for each parse session.","For deferred/lazy iteration, materialize the nodes (e.g. via XamlServices.Transform into a XamlWriter) before disposing the reader.","Track disposal state in your pipeline and stop issuing Read calls once disposed."],"exampleFix":"// before\nusing (var reader = new XamlXmlReader(stream)) {\n    return ReadLazy(reader); // caller iterates after using exits -> disposed\n}\n\n// after\nXamlXmlReader Create() {\n    // caller owns lifetime; do not dispose here\n    return new XamlXmlReader(stream);\n}","handlingStrategy":"validation","validationCode":"if (reader.IsDisposed) throw new ObjectDisposedException(nameof(reader));\nreader.Read();","typeGuard":null,"tryCatchPattern":"try { while (reader.Read()) { /* consume */ } }\ncatch (ObjectDisposedException) { /* reader released upstream; stop iterating */ }","preventionTips":["Scope the reader's using block to enclose the entire consumption loop, not just creation.","Never hand a reader to a deferred iterator that outlives its disposal — materialize nodes first.","Create a fresh XamlXmlReader for each parse session; never reuse a disposed one."],"tags":["xaml","object-disposed","xamlreader","lifetime"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}