{"record":{"id":"6e4f61deb3f9a30e","repo":"jstedfast/MailKit","slug":"the-stream-does-not-support-resizing","errorCode":null,"errorMessage":"The stream does not support resizing.","messagePattern":"The stream does not support resizing\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/ProgressStream.cs","lineNumber":182,"sourceCode":"\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);\n\t\t}\n\n\t\tpublic override void SetLength (long value)\n\t\t{\n\t\t\tthrow new NotSupportedException (\"The stream does not support resizing.\");\n\t\t}\n\t}\n}\n","sourceCodeStart":164,"sourceCodeEnd":186,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/ProgressStream.cs#L164-L186","documentation":"ProgressStream.SetLength always throws NotSupportedException with \"The stream does not support resizing.\" A progress-reporting wrapper over a read-only source stream has no mechanism to change the underlying stream's length, so resizing is explicitly rejected.","triggerScenarios":"Calling stream.SetLength(n) on a ProgressStream; indirectly via APIs that truncate streams (e.g. File stream helpers, SetLength called by writer classes).","commonSituations":"Treating the progress-wrapped network stream like a writable file stream; generic stream-handling utility code that calls SetLength on all Stream instances.","solutions":["Do not resize a ProgressStream; it is for reading/monitoring only","Perform SetLength on the underlying source stream directly if it genuinely supports it","Check CanWrite/CanSeek before attempting resize operations"],"exampleFix":"// before\nprogressStream.SetLength(0);\n// after\nif (source.CanWrite)\n    source.SetLength(0);\nelse\n    throw new NotSupportedException(\"The wrapped source stream cannot be resized\");","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"bool CanResize(Stream s) => s.CanWrite && s.CanSeek; // ProgressStream never satisfies this for SetLength","tryCatchPattern":"try { stream.SetLength(0); }\ncatch (NotSupportedException) { /* resize the underlying source instead */ }","preventionTips":["Do not resize progress-wrapped streams; operate on the raw source","Check CanWrite before write/resize operations","Use ProgressStream only for read-monitoring scenarios"],"tags":["not-supported","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"}