{"record":{"id":"6b8a641c1280284d","repo":"jstedfast/MailKit","slug":"the-stream-does-not-support-seeking","errorCode":null,"errorMessage":"The stream does not support seeking.","messagePattern":"The stream does not support seeking\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/ProgressStream.cs","lineNumber":159,"sourceCode":"\t\tpublic override void Write (byte[] buffer, int offset, int count)\n\t\t{\n\t\t\tSource.Write (buffer, offset, count);\n\n\t\t\tif (count > 0)\n\t\t\t\tUpdate (count);\n\t\t}\n\n\t\tpublic override async Task WriteAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)\n\t\t{\n\t\t\tawait Source.WriteAsync (buffer, offset, count, cancellationToken).ConfigureAwait (false);\n\n\t\t\tif (count > 0)\n\t\t\t\tUpdate (count);\n\t\t}\n\n\t\tpublic override long Seek (long offset, SeekOrigin origin)\n\t\t{\n\t\t\tthrow new NotSupportedException (\"The stream does not support seeking.\");\n\t\t}\n\n\t\tpublic void Flush (CancellationToken cancellationToken)\n\t\t{\n\t\t\tif (cancellable != null)\n\t\t\t\tcancellable.Flush (cancellationToken);\n\t\t\telse\n\t\t\t\tSource.Flush ();\n\t\t}\n\n\t\tpublic override void Flush ()\n\t\t{\n\t\t\tSource.Flush ();\n\t\t}\n\n\t\tpublic override Task FlushAsync (CancellationToken cancellationToken)\n\t\t{\n\t\t\treturn Source.FlushAsync (cancellationToken);","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/ProgressStream.cs#L141-L177","documentation":"ProgressStream.Seek is deliberately not implemented: the wrapper exists to report read progress on forward-only streams (e.g. network/HTTP streams), which cannot reposition. It throws NotSupportedException with the message \"The stream does not support seeking.\" whenever Seek is called.","triggerScenarios":"Calling stream.Seek(...) or stream.Position = ... on a ProgressStream; setting Stream.Position (which internally calls Seek); code paths like TestSeek or reading Position that require seekability.","commonSituations":"Passing a ProgressStream to APIs that assume a seekable Stream (media players, ZipArchive with default mode, serializers that rewind); copying code that worked with FileStream/ MemoryStream to a network-backed stream.","solutions":["Avoid seeking; read the stream sequentially from start to end","If random access is needed, buffer the source into a MemoryStream first and wrap that in ProgressStream","Check CanSeek before calling Seek and use an alternative code path"],"exampleFix":"// before\nprogressStream.Seek(0, SeekOrigin.Begin);\n// after\nif (progressStream.CanSeek)\n    progressStream.Seek(0, SeekOrigin.Begin);\nelse {\n    using var buffered = new MemoryStream();\n    progressStream.CopyTo(buffered);\n    buffered.Seek(0, SeekOrigin.Begin);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"bool CanSeekSafely(Stream s) => s.CanSeek; // check before calling Seek/Position","tryCatchPattern":"try { stream.Seek(0, SeekOrigin.Begin); }\ncatch (NotSupportedException) { /* non-seekable: buffer or re-open instead */ }","preventionTips":["Check Stream.CanSeek before any Seek or Position assignment","Copy to MemoryStream when random access is required","Treat network-backed streams as forward-only"],"tags":["not-supported","seek","stream","mailkit"],"backgroundTag":"unsupported-operation","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}