{"record":{"id":"1791dfbf41c3747e","repo":"dotnet/wpf","slug":"sr-streamdoesnotsupportseek","errorCode":null,"errorMessage":"SR.StreamDoesNotSupportSeek","messagePattern":"SR\\.StreamDoesNotSupportSeek","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs","lineNumber":67,"sourceCode":"            _predefinedNamespaces.Add(new Uri(AnnotationXmlConstants.Namespaces.BaseSchemaNamespace), null);\n            _predefinedNamespaces.Add(new Uri(XamlReaderHelper.DefaultNamespaceURI), null);\n        }\n\n        /// <summary>\n        ///     Creates an instance using the XML stream passed in as the\n        ///     content. The XML in the stream must be valid XML and conform\n        ///     to the CAF 2.0 schema.\n        /// </summary>\n        /// <param name=\"stream\">stream containing annotation data in XML format</param>\n        /// <exception cref=\"ArgumentNullException\">stream is null</exception>\n        /// <exception cref=\"XmlException\">stream contains invalid XML</exception>\n        public XmlStreamStore(Stream stream)\n            : base()\n        {\n            ArgumentNullException.ThrowIfNull(stream);\n\n            if (!stream.CanSeek)\n                throw new ArgumentException(SR.StreamDoesNotSupportSeek);\n\n            SetStream(stream, null);\n        }\n\n        /// <summary>\n        ///     Creates an instance using the XML stream passed in as the\n        ///     content. The XML in the stream must be valid XML and conform\n        ///     to the Annotations V1 schema or a valid future version XML which\n        ///     compatibility rules are that when applied they will produce\n        ///     a valid Annotations V1 XML. This .ctor allows registration of\n        ///     application specific known namespaces.\n        /// </summary>\n        /// <param name=\"stream\">stream containing annotation data in XML format</param>\n        /// <param name=\"knownNamespaces\">A dictionary with known and compatible namespaces. The keys in\n        /// this dictionary are known namespaces. The value of each key is a list of namespaces that are compatible with\n        /// the key one, i.e. each of the namespaces in the value list will be transformed to the\n        /// key namespace while reading the input XML.</param>\n        /// <exception cref=\"ArgumentNullException\">stream is null</exception>","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs#L49-L85","documentation":"The XmlStreamStore(Stream) constructor requires a seekable stream because the store must reposition within the annotation XML stream. If stream.CanSeek is false it throws ArgumentException(SR.StreamDoesNotSupportSeek). Non-seekable streams (e.g. network or decompression streams read straight through) cannot back the store.","triggerScenarios":"new XmlStreamStore(new NetworkStream(...)), new XmlStreamStore(responseStream) from an HttpClient response body, or a CryptoStream/DeflateStream chain where CanSeek is false.","commonSituations":"Downloading annotation files over HTTP and passing the response stream directly; wrapping the store around a compression stream; piping streams between processes.","solutions":["Copy the stream into a seekable MemoryStream first, then construct the store.","Write the data to a FileStream and construct the store from the file stream.","If you control the source, supply a stream type with CanSeek == true (e.g. FileStream, MemoryStream)."],"exampleFix":"// before\nusing var store = new XmlStreamStore(httpResponseStream); // throws: not seekable\n// after\nusing var ms = new MemoryStream();\nhttpResponseStream.CopyTo(ms);\nms.Position = 0;\nusing var store = new XmlStreamStore(ms);","handlingStrategy":"type-guard","validationCode":"if (!stream.CanSeek)\n{\n    var ms = new MemoryStream();\n    stream.CopyTo(ms);\n    ms.Position = 0;\n    stream = ms;\n}","typeGuard":"static Stream EnsureSeekable(Stream s) => s.CanSeek ? s : (() => { var ms = new MemoryStream(); s.CopyTo(ms); ms.Position = 0; return (Stream)ms; })();","tryCatchPattern":"try { using var store = new XmlStreamStore(stream); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"seek\")) { /* buffer into MemoryStream and retry */ }","preventionTips":["Check Stream.CanSeek before constructing XmlStreamStore.","Buffer network/decompression streams into MemoryStream or FileStream first.","Do not pass live HTTP response streams directly to APIs that require seeking."],"tags":["wpf","annotations","stream","io"],"backgroundTag":"unsupported-operation","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"}