stride3d/stride · error · InvalidOperationException

Central directory currently does not exist

Error message

Central directory currently does not exist

What it means

GetAllEntries iterates the cached central-directory image, which only exists after the archive's central directory was successfully read during construction. If centralDirImage is null, the archive is invalid or uninitialized and enumeration cannot proceed.

Solutions

  1. Validate the zip file (signature, size) before opening; re-download if truncated
  2. Recreate the ZipFile over a fresh, complete stream
  3. Wrap construction and GetAllEntries in a check that the constructor succeeded (no swallowed exceptions)

Example fix

// before
var zip = GetCachedZip(); // may have failed init
var entries = zip.GetAllEntries();
// after
if (zip == null || zip.GetAllEntriesOrNull() == null) throw new InvalidDataException("Archive is corrupt");
var entries = zip.GetAllEntries();
Defensive patterns

Strategy: try-catch

Validate before calling

if (new FileInfo(zipPath).Length == 0) throw new InvalidDataException("Zip file is empty");

Try / catch

try { entries = zip.GetAllEntries(); }
catch (InvalidOperationException) { throw new InvalidDataException($"Archive {zipPath} is corrupt or truncated"); }

Prevention

When it happens

Trigger: Calling GetAllEntries on a ZipFile instance whose ReadFileInfo failed or whose underlying stream was empty/corrupt, or on an archive truncated mid-download.

Common situations: Partially downloaded zip files, zero-byte placeholder files, or reusing a ZipFile after the underlying stream was disposed/reset.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/1192210cbd1f8c64. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.IO/System.IO.Compression.Zip/ZipFile.cs:416

            inStream.Read(buffer, 0, buffer.Length);

            if (zfe.Method == Compression.Deflate)
                inStream.Dispose();

            return true;
        }

        /// <summary>
        /// Read all the file records in the central directory 
        /// </summary>
        /// <returns>
        /// List of all entries in directory.
        /// </returns>
        public ZipFileEntry[] GetAllEntries()
        {
            if (this.centralDirImage == null)
            {
                throw new InvalidOperationException("Central directory currently does not exist");
            }

            var result = new List<ZipFileEntry>();

            int pointer = 0;
            while (pointer < this.centralDirImage.Length)
            {
                uint signature = BitConverter.ToUInt32(this.centralDirImage, pointer);
                if (signature != 0x02014b50)
                {
                    break;
                }

                result.Add(this.GetEntry(ref pointer));
            }

            return result.ToArray();
        }

View on GitHub (pinned to 96fad776d2)