{"record":{"id":"c2152ea37c0780d9","repo":"dotnet/wpf","slug":"stream-does-not-support-read","errorCode":null,"errorMessage":"Stream does not support Read","messagePattern":"Stream does not support Read","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlStream.cs","lineNumber":662,"sourceCode":"        /// </summary>\n        public override long Position\n        {\n            get\n            {\n                return -1;\n            }\n            set\n            {\n                throw new NotSupportedException();\n            }\n        }\n\n        /// <summary>\n        /// Override of Stream.Read\n        /// </summary>\n        public override int Read(byte[] buffer, int offset, int count)\n        {\n            throw new NotSupportedException();\n        }\n\n        /// <summary>\n        /// Override of Stream.ReadByte\n        /// </summary>\n        public override int ReadByte()\n        {\n            throw new NotSupportedException();\n        }\n\n        /// <summary>\n        /// Override of Stream.Seek\n        /// </summary>\n        public override long Seek(long offset, SeekOrigin loc)\n        {\n            return StreamManager.WriterSeek(offset,loc);\n        }\n","sourceCodeStart":644,"sourceCodeEnd":680,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlStream.cs#L644-L680","documentation":"The WriterStream in XamlStream is write-only: its Read override unconditionally throws NotSupportedException. Any attempt to read bytes from this stream fails because it only feeds data from the BAML writer to the reader.","triggerScenarios":"Calling Read/ReadByte (directly or via helpers like StreamReader, CopyTo, ToArray-style reads) on the XamlStream writer stream.","commonSituations":"Generic stream utilities (CopyTo, reading back what was written, hashing content) applied to the write half of the internal XAML parser pipe.","solutions":["Read from the corresponding reader side of the XamlStream instead of the writer stream.","Write to a MemoryStream if you later need to read the bytes back, and feed that to the API.","Remove read operations from code paths that only own the writer stream."],"exampleFix":"// before\nint b = writerStream.ReadByte(); // throws\n// after\nwriterStream.Write(data, 0, data.Length);\n// read from the XamlStream reader side instead:\nint b = xamlStreamReader.Read();","handlingStrategy":"type-guard","validationCode":"if (!stream.CanRead) throw new InvalidOperationException(\"This stream is write-only\");","typeGuard":"bool canRead = stream is { CanRead: true };","tryCatchPattern":"try { stream.Read(buffer, 0, count); }\ncatch (NotSupportedException) { /* use the reader side of the XamlStream instead */ }","preventionTips":["Check CanRead before reading from any stream.","Read only from the XamlStream reader side; the writer stream is write-only.","Keep a MemoryStream copy if you need to re-read written bytes."],"tags":["wpf","xaml","io","stream"],"backgroundTag":"operation-not-supported","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"}