stride3d/stride · error · InvalidOperationException
Not a valid zip entry.
Error message
Not a valid zip entry.
What it means
ReadFile seeks to the entry's stored header offset and verifies the local file header signature (0x04034b50, 'PK\x03\x04'). A mismatch means the data at that offset is not the expected local entry header, so reading is aborted.
Solutions
- Re-create the ZipFile and re-query GetAllEntries before reading if the archive may have changed
- Ensure the ZipFileEntry came from the same ZipFile instance over the same stream
- Verify the archive's integrity (test extraction or checksum) before reading
Example fix
// before var entries = oldZip.GetAllEntries(); // stale using var zip = new ZipFile(newStream); zip.ReadFile(entries[0]); // after using var zip = new ZipFile(newStream); var entry = zip.GetAllEntries().First(e => e.Filename == name); zip.ReadFile(entry);
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure entries are fresh from the same live ZipFile instance
var freshEntry = liveZip.GetAllEntries().FirstOrDefault(e => e.Filename == entry.Filename);
if (freshEntry is null) throw new InvalidOperationException("Entry no longer exists in archive"); Try / catch
try { zip.ReadFile(entry); }
catch (InvalidOperationException) { throw new InvalidDataException($"Zip entry '{entry.Filename}' has a corrupt header"); } Prevention
- Never cache ZipFileEntry values across archive modifications or stream reopenings
- Always read entries obtained from the same ZipFile instance
- Test archive integrity after any merge/append operation
When it happens
Trigger: Calling ReadFile with a ZipFileEntry whose HeaderOffset points at wrong/garbage data: the archive was modified after entries were listed, offsets came from a different ZipFile instance, or the file was corrupted/truncated.
Common situations: Merging or appending to zip files then reading stale entries, caching entries across stream reopen where the file changed, data-descriptor entries with outdated offsets.
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
- Central directory currently does not exist
- Stream cannot seek
- Stream cannot be written
- File doesn't appear to be a valid package
- Package file [ ] was not found
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/55afc04ad9a41520.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.IO/System.IO.Compression.Zip/ZipFile.cs:456
/// </summary>
/// <param name="zfe">
/// Entry information of file to extract
/// </param>
/// <returns>
/// Stream to store the uncompressed data
/// </returns>
/// <remarks>
/// Unique compression methods are Store and Deflate
/// </remarks>
public Stream ReadFile(ZipFileEntry zfe)
{
// check signature
var signature = new byte[4];
this.zipFileStream.Seek(zfe.HeaderOffset, SeekOrigin.Begin);
this.zipFileStream.Read(signature, 0, 4);
if (BitConverter.ToUInt32(signature, 0) != 0x04034b50)
{
throw new InvalidOperationException("Not a valid zip entry.");
}
// Select input stream for inflating or just reading
Stream inStream;
switch (zfe.Method)
{
case Compression.Store:
inStream = this.zipFileStream;
break;
case Compression.Deflate:
inStream = new DeflateStream(this.zipFileStream, CompressionMode.Decompress, true);
break;
default:
throw new InvalidOperationException("Not a valid zip entry.");
}
this.zipFileStream.Seek(zfe.FileOffset, SeekOrigin.Begin);
View on GitHub (pinned to 96fad776d2)