{"record":{"id":"52b391a99ad85f18","repo":"dotnet/wpf","slug":"sr-streamnotset","errorCode":null,"errorMessage":"SR.StreamNotSet","messagePattern":"SR\\.StreamNotSet","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs","lineNumber":933,"sourceCode":"                    navigator = (XPathNavigator)iterator.Current;\n                }\n            }\n\n            return navigator;\n        }\n\n        /// <summary>\n        ///    Verifies the store is in a valid state.  Throws exceptions otherwise.\n        /// </summary>\n        private void CheckStatus()\n        {\n            lock (SyncRoot)\n            {\n                if (IsDisposed)\n                    throw new ObjectDisposedException(null, SR.ObjectDisposed_StoreClosed);\n\n                if (_stream == null)\n                    throw new InvalidOperationException(SR.StreamNotSet);\n            }\n        }\n\n        /// <summary>\n        /// Called from flush to serialize all annotations in the map\n        /// notice that delete takes care of the delete action both in the map\n        /// and in the store\n        /// </summary>\n        private void SerializeAnnotations()\n        {\n            List<Annotation> mapAnnotations = _storeAnnotationsMap.FindDirtyAnnotations();\n            foreach (Annotation annotation in mapAnnotations)\n            {\n                XPathNavigator editor = GetAnnotationNodeForId(annotation.Id);\n                if (editor == null)\n                {\n                    editor = (XPathNavigator)_rootNavigator.CreateNavigator();\n                    XmlWriter writer = editor.AppendChild();","sourceCodeStart":915,"sourceCodeEnd":951,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs#L915-L951","documentation":"XmlStreamStore.CheckStatus() throws InvalidOperationException (SR.StreamNotSet) when the store was constructed without a backing Stream (_stream == null). The store needs a stream to read/write annotation XML; without one no operation can proceed. This is a configuration error at store construction.","triggerScenarios":"Creating XmlStreamStore with the parameterless/default path that does not assign a stream, then calling AddAnnotation, DeleteAnnotation, GetAnnotation, Flush, FindAnnotationIds, or InternalGetAnnotations.","commonSituations":"Using a constructor overload that defers stream assignment and forgetting to set it; passing a stream that was disposed and nulled elsewhere; copy-pasting store setup code and dropping the stream argument.","solutions":["Construct the XmlStreamStore with a valid Stream (e.g. new XmlStreamStore(stream))","If a custom subclass, assign _stream (or call the base constructor with the stream) before use","Check _stream != null (or wrap setup) before performing operations"],"exampleFix":"// before\nvar store = new XmlStreamStore();\nstore.Flush(); // InvalidOperationException: StreamNotSet\n\n// after\nusing var stream = File.Open(\"annotations.xml\", FileMode.OpenOrCreate);\nvar store = new XmlStreamStore(stream);\nstore.Flush();","handlingStrategy":"validation","validationCode":"// Ensure a stream-backed store before use\nvar store = stream != null ? new XmlStreamStore(stream) : throw new InvalidOperationException(\"Annotation stream not initialized\");","typeGuard":null,"tryCatchPattern":"try { store.AddAnnotation(a); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"stream\", StringComparison.OrdinalIgnoreCase)) { InitializeStreamAndRetry(); }","preventionTips":["Always construct XmlStreamStore with a Stream argument","Keep stream lifetime aligned with store lifetime (own both in one class)","Fail fast at startup if the annotation stream cannot be opened"],"tags":["wpf","annotations","missing-stream","invalid-state"],"backgroundTag":"missing-required-config-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}