stride3d/stride · error · InvalidOperationException
Stream cannot seek
Error message
Stream cannot seek
What it means
The ZipFile(Stream) constructor needs to seek backward to locate the end-of-central-directory record. A non-seekable stream (e.g. network or pipe stream) cannot be read as an archive, so the constructor throws immediately.
Solutions
- Copy the stream into a MemoryStream or a temporary FileStream first, then open the ZipFile over that
- For HTTP, use a stream that supports seeking (e.g. write response to disk)
- Check stream.CanSeek before constructing to give a clearer error
Example fix
// before using var zip = new ZipFile(responseStream); // after using var ms = new MemoryStream(); responseStream.CopyTo(ms); ms.Position = 0; using var zip = new ZipFile(ms);
Defensive patterns
Strategy: validation
Validate before calling
if (!stream.CanSeek) { using var ms = new MemoryStream(); stream.CopyTo(ms); ms.Position = 0; return new ZipFile(ms); } Type guard
static bool IsSeekable(Stream s) => s.CanSeek;
Try / catch
try { zip = new ZipFile(stream); }
catch (InvalidOperationException) { /* buffer to MemoryStream and retry */ } Prevention
- Check stream.CanSeek before archive APIs
- Buffer network/pipe/deflate streams to disk or memory before opening archives
- Document that ZipFile requires a seekable stream
When it happens
Trigger: Constructing ZipFile from a raw NetworkStream, the body of an HTTP response stream read directly, a compressed/deflate stream, or a console/pipe stream.
Common situations: Downloading a zip directly into ZipFile without buffering, wrapping a GZipStream and passing it as the zip stream.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Stream cannot be written
- Central directory currently does not exist
- Not a valid zip entry.
- You cannot modify this stream.
- Operation 'Read' is not supported
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/7eda7ec41f2c0972.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.IO/System.IO.Compression.Zip/ZipFile.cs:82
{
this.FileName = filename;
}
/// <summary>
/// Initializes a new instance of the <see cref="ZipFile"/> class.
/// Method to open an existing storage from stream
/// </summary>
/// <param name="stream">
/// Already opened stream with zip contents
/// </param>
/// <returns>
/// A valid ZipFile object
/// </returns>
public ZipFile(Stream stream)
{
if (!stream.CanSeek)
{
throw new InvalidOperationException("Stream cannot seek");
}
this.zipFileStream = stream;
if (!this.ReadFileInfo())
{
throw new Exception();
}
this.FileName = string.Empty;
}
#endregion
#region Public Properties
/// <summary>
/// Gets the number of entries in the zip file.View on GitHub (pinned to 96fad776d2)