{"record":{"id":"5fbd81b6f5d32acf","repo":"stride3d/stride","slug":"you-cannot-modify-this-stream","errorCode":null,"errorMessage":"You cannot modify this stream.","messagePattern":"You cannot modify this stream\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.IO/System.IO.Compression.Zip/ZipStream.cs","lineNumber":141,"sourceCode":"        /// </summary>\n        public override void Close()\n        {\n            base.Close();\n\n            if (this.zipFileEntry.Method == Compression.Deflate)\n            {\n                this.innerStream.Dispose();\n            }\n        }\n\n        /// <summary>\n        /// The flush.\n        /// </summary>\n        /// <exception cref=\"InvalidOperationException\">\n        /// </exception>\n        public override void Flush()\n        {\n            throw new InvalidOperationException(\"You cannot modify this stream.\");\n        }\n\n        /// <summary>\n        /// The read.\n        /// </summary>\n        /// <param name=\"buffer\">\n        /// The buffer.\n        /// </param>\n        /// <param name=\"offset\">\n        /// The offset.\n        /// </param>\n        /// <param name=\"count\">\n        /// The count.\n        /// </param>\n        /// <returns>\n        /// The read.\n        /// </returns>\n        public override int Read(byte[] buffer, int offset, int count)","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.IO/System.IO.Compression.Zip/ZipStream.cs#L123-L159","documentation":"ZipStream is a read-only stream over a zip entry; Flush() is overridden to always throw InvalidOperationException because flushing would imply modifying the underlying archive. Calling Flush on a ZipStream is always a programming error.","triggerScenarios":"Calling stream.Flush() (directly or via StreamWriter/CryptoStream wrappers that flush on Dispose) on a ZipStream obtained from ZipFile.OpenFile/ReadFile.","commonSituations":"Wrapping ZipStream in a StreamWriter whose Dispose flushes the stream, or copying defensive Flush calls from code written for writable streams.","solutions":["Remove the Flush() call on ZipStream","Flush or dispose the wrapper writer without flushing the base stream (e.g. leave open and dispose carefully)","Only flush streams known to be writable","Guard flush calls behind a CanWrite check"],"exampleFix":"// before\nusing (var writer = new StreamWriter(zipStream))\n{\n    writer.WriteLine(text);\n    zipStream.Flush(); // throws\n}\n// after\nusing (var reader = new StreamReader(zipStream))\n{\n    var text = reader.ReadToEnd(); // read-only usage, no flush needed\n}","handlingStrategy":"try-catch","validationCode":"if (!stream.CanWrite) { /* skip flush */ }","typeGuard":"static bool IsWritableStream(Stream s) => s.CanWrite;","tryCatchPattern":"try { stream.Flush(); } catch (InvalidOperationException) { /* ZipStream is read-only; safe to ignore */ }","preventionTips":["Treat ZipStream as strictly read-only","Avoid wrapping it in writers that flush on dispose","Check Stream.CanWrite before flush operations"],"tags":["zip","stream","read-only"],"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"}