{"record":{"id":"e732a13b307ec36a","repo":"stride3d/stride","slug":"stream-cannot-be-written","errorCode":null,"errorMessage":"Stream cannot be written","messagePattern":"Stream cannot be written","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.IO/System.IO.Compression.Zip/ZipFile.cs","lineNumber":325,"sourceCode":"        /// Copy the contents of a stored file into an opened stream\n        /// </summary>\n        /// <param name=\"zfe\">\n        /// Entry information of file to extract\n        /// </param>\n        /// <param name=\"stream\">\n        /// Stream to store the uncompressed data\n        /// </param>\n        /// <returns>\n        /// True if success, false if not.\n        /// </returns>\n        /// <remarks>\n        /// Unique compression methods are Store and Deflate\n        /// </remarks>\n        public bool ExtractFile(ZipFileEntry zfe, Stream stream)\n        {\n            if (!stream.CanWrite)\n            {\n                throw new InvalidOperationException(\"Stream cannot be written\");\n            }\n\n            // check signature\n            var signature = new byte[4];\n            this.zipFileStream.Seek(zfe.HeaderOffset, SeekOrigin.Begin);\n            this.zipFileStream.Read(signature, 0, 4);\n            if (BitConverter.ToUInt32(signature, 0) != 0x04034b50)\n            {\n                return false;\n            }\n\n            // Select input stream for inflating or just reading\n            Stream inStream = this.GetZipStream(zfe);\n            if (inStream == null)\n            {\n                return false;\n            }\n","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.IO/System.IO.Compression.Zip/ZipFile.cs#L307-L343","documentation":"ExtractFile decompresses an entry into the supplied destination stream, which must be writable. Passing a read-only stream would make every write fail mid-extraction, so it is rejected upfront with InvalidOperationException.","triggerScenarios":"Calling ExtractFile(entry, stream) with a FileStream opened with FileAccess.Read, a MemoryStream created over a read-only buffer via new MemoryStream(byte[]), or any readonly wrapper stream.","commonSituations":"Extracting into a file opened for reading to 'check' it, writing back to the same stream used for reading the archive.","solutions":["Open the destination with FileAccess.Write / FileMode.Create","If you only need entry data in memory, pass a new MemoryStream() instead","Check stream.CanWrite before calling"],"exampleFix":"// before\nusing var dst = File.OpenRead(path);\nzip.ExtractFile(entry, dst);\n// after\nusing var dst = File.Create(path);\nzip.ExtractFile(entry, dst);","handlingStrategy":"validation","validationCode":"if (!stream.CanWrite) throw new ArgumentException(\"Destination stream must be writable\", nameof(stream));","typeGuard":"static bool IsWritable(Stream s) => s.CanWrite;","tryCatchPattern":"try { zip.ExtractFile(entry, stream); }\ncatch (InvalidOperationException ex) { throw new IOException(\"Destination stream is not writable\", ex); }","preventionTips":["Open destinations with FileAccess.Write/FileMode.Create","Use fresh MemoryStream for in-memory extraction","Never pass the archive's own read stream as the destination"],"tags":["io","zip","stream"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}