{"record":{"id":"9ea18c3e100dfa72","repo":"stride3d/stride","slug":"zip-archive-are-read-only","errorCode":null,"errorMessage":"ZIP archive are read-only.","messagePattern":"ZIP archive are read-only\\.","errorType":"exception","errorClass":"UnauthorizedAccessException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.IO/ZipFileSystemProvider.cs","lineNumber":68,"sourceCode":"                filePath = null;\n                start = 0;\n                end = -1;\n                return false;\n            }\n\n            filePath = zipFile.FileName;\n            start = zipFileEntry.FileOffset;\n            end = zipFileEntry.FileOffset + zipFileEntry.FileSize;\n            return true;\n        }\n\n        public override Stream OpenStream(string url, VirtualFileMode mode, VirtualFileAccess access, VirtualFileShare share = VirtualFileShare.Read, StreamFlags streamType = StreamFlags.None)\n        {\n            if (!zipFileEntries.TryGetValue(url, out var zipFileEntry))\n                throw new FileNotFoundException(\"File not found inside ZIP archive.\");\n\n            if (mode != VirtualFileMode.Open || access != VirtualFileAccess.Read)\n                throw new UnauthorizedAccessException(\"ZIP archive are read-only.\");\n\n            lock (zipFile)\n            {\n                if (zipFileEntry.Method == Compression.Store)\n                {\n                    // Open a VirtualFileStream on top of Zip FileStream\n                    return new VirtualFileStream(new FileStream(zipFileEntry.ZipFileName, FileMode.Open, FileAccess.Read), zipFileEntry.FileOffset, zipFileEntry.FileOffset + zipFileEntry.FileSize);\n                }\n\n                // Decompress it into a MemoryStream\n                var buffer = new byte[zipFileEntry.FileSize];\n                zipFile.ExtractFile(zipFileEntry, buffer);\n                return new MemoryStream(buffer);\n            }\n        }\n\n        public override bool DirectoryExists(string url)\n        {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.IO/ZipFileSystemProvider.cs#L50-L86","documentation":"ZipFileSystemProvider supports only read access: OpenStream throws UnauthorizedAccessException when mode is not VirtualFileMode.Open or access is not VirtualFileAccess.Read, because ZIP archives loaded by this provider cannot be written.","triggerScenarios":"Calling OpenStream with VirtualFileMode.Create/New/CreateNew/OpenOrCreate or VirtualFileAccess.Write/ReadWrite on a ZIP-backed provider.","commonSituations":"Code shared between disk and ZIP providers that opens files for writing; savegame/config writes pointed at a bundled ZIP asset mount; copying a write path from a FileSystemProvider implementation.","solutions":["Use VirtualFileMode.Open with VirtualFileAccess.Read when reading from ZIP providers.","Redirect write operations to a writable FileSystemProvider mount instead of the ZIP.","Guard writes: check the provider type (is ZipFileSystemProvider) and route to a writable provider.","Use WriteAllData-style helpers only on writable mounts."],"exampleFix":"// before\nvar s = zipProvider.OpenStream(url, VirtualFileMode.Create, VirtualFileAccess.Write);\n// after\nvar s = zipProvider.OpenStream(url, VirtualFileMode.Open, VirtualFileAccess.Read); // ZIPs are read-only\n// write elsewhere:\n// writableProvider.OpenStream(url, VirtualFileMode.Create, VirtualFileAccess.Write);","handlingStrategy":"type-guard","validationCode":"bool isReadOnly = provider is ZipFileSystemProvider;\nif (isReadOnly && (mode != VirtualFileMode.Open || access != VirtualFileAccess.Read))\n    throw new InvalidOperationException(\"ZIP providers are read-only; use a writable mount.\");","typeGuard":"bool IsZipProvider(IVirtualFileProvider p) => p is ZipFileSystemProvider;","tryCatchPattern":"try { stream = provider.OpenStream(url, mode, access); }\ncatch (UnauthorizedAccessException) { stream = fallbackWritableProvider.OpenStream(url, mode, access); }","preventionTips":["Route all writes to FileSystemProvider-backed mounts, never ZIP mounts","Use read-only access constants for bundled assets","Encode provider capability (read-only) in your mount registry"],"tags":["filesystem","zip","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"}