{"record":{"id":"b8fc2f20e79c029d","repo":"dotnet/wpf","slug":"sr-xpsserializerfactory-writerisclosed-b8fc2f","errorCode":null,"errorMessage":"SR.XpsSerializerFactory_WriterIsClosed","messagePattern":"SR\\.XpsSerializerFactory_WriterIsClosed","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/SerializerFactory/XpsSerializerWriterCollator.cs","lineNumber":119,"sourceCode":"        /// <summary>\n        /// Cancel Write\n        /// </summary>\n        public override void Cancel()\n        {\n            CheckDisposed();\n\n            _collator.Cancel();\n        }\n\n        #endregion\n\n        #region Private Methods\n\n        private void CheckDisposed()\n        {\n            if (_collator == null)\n            {\n                throw new XpsSerializationException(SR.XpsSerializerFactory_WriterIsClosed);\n            }\n        }\n\n        #endregion\n\n        #region Data\n\n        private VisualsToXpsDocument        _collator;\n        private Package                     _package;\n        private XpsDocument                 _xpsDocument;\n\n        #endregion\n    }\n}\n","sourceCodeStart":101,"sourceCodeEnd":134,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/SerializerFactory/XpsSerializerWriterCollator.cs#L101-L134","documentation":"XpsSerializerWriterCollator.CheckDisposed throws XpsSerializationException(SR.XpsSerializerFactory_WriterIsClosed) when the underlying collator (_collator) has been released. It is called by Write, WriteAsync, Close, CancelAsync, and Cancel, so any use of a closed collator fails with this error.","triggerScenarios":"Calling Write, WriteAsync, Close, CancelAsync, or Cancel on an XpsSerializerWriterCollator after it was closed and its internal _collator set to null.","commonSituations":"Writing additional pages after Close; double-Close; Cancel/CancelAsync invoked after the collator finished and released its resources.","solutions":["Stop using the collator after Close; obtain a fresh collator from the serializer for new content.","Ensure Close/Cancel is called only once and track the closed state.","Guard collation code paths with a disposed flag."],"exampleFix":"// before\ncollator.Close();\ncollator.Write(canvas); // throws\n// after\ncollator.Close();\ncollator = serializer.CreateVisualsCollator();\ncollator.Write(canvas);","handlingStrategy":"type-guard","validationCode":"if (collator == null || collator.IsClosed) throw new InvalidOperationException(\"collator already closed\");","typeGuard":"bool CollatorUsable(XpsSerializerWriterCollator c) => c != null && !c.IsDisposed;","tryCatchPattern":"try { collator.Write(visual); }\ncatch (XpsSerializationException) when (closed) { /* recreate collator */ }","preventionTips":["Call Close/Cancel exactly once and guard with a bool flag.","Don't write pages after Close; create a new collator for new content.","Keep collator lifetime scoped to the document being produced."],"tags":["wpf","xps","object-disposed","collator-closed"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}