{"record":{"id":"bafdea726278244b","repo":"jstedfast/MailKit","slug":"notsupportedexception","errorCode":null,"errorMessage":"NotSupportedException","messagePattern":"NotSupportedException","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/DuplexStream.cs","lineNumber":363,"sourceCode":"\t\tpublic override Task FlushAsync (CancellationToken cancellationToken)\n\t\t{\n\t\t\tCheckDisposed ();\n\n\t\t\treturn OutputStream.FlushAsync (cancellationToken);\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Sets the position within the current stream.\n\t\t/// </summary>\n\t\t/// <returns>The new position within the stream.</returns>\n\t\t/// <param name=\"offset\">The offset into the stream relative to the <paramref name=\"origin\"/>.</param>\n\t\t/// <param name=\"origin\">The origin to seek from.</param>\n\t\t/// <exception cref=\"System.NotSupportedException\">\n\t\t/// The stream does not support seeking.\n\t\t/// </exception>\n\t\tpublic override long Seek (long offset, SeekOrigin origin)\n\t\t{\n\t\t\tthrow new NotSupportedException ();\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Sets the length of the stream.\n\t\t/// </summary>\n\t\t/// <param name=\"value\">The desired length of the stream in bytes.</param>\n\t\t/// <exception cref=\"System.NotSupportedException\">\n\t\t/// The stream does not support setting the length.\n\t\t/// </exception>\n\t\tpublic override void SetLength (long value)\n\t\t{\n\t\t\tthrow new NotSupportedException ();\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Releases the unmanaged resources used by the <see cref=\"DuplexStream\"/> and\n\t\t/// optionally releases the managed resources.\n\t\t/// </summary>","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/DuplexStream.cs#L345-L381","documentation":"DuplexStream.Seek always throws NotSupportedException: a duplex pipe stream cannot reposition its read/write cursor. Seeking is fundamentally unsupported on this stream type, as documented via its exception cref.","triggerScenarios":"Calling Seek(offset, origin) on a DuplexStream, directly or indirectly via helpers like Position =, StreamReader with a nonzero buffer offset, or Stream.Seek-based rewinding.","commonSituations":"Passing the stream to parsers or utilities that call Seek to retry/reparse (e.g. MIME parsers expecting buffered streams); mixing code paths shared with FileStream.","solutions":["Remove Seek usage; read strictly forward from the current position.","Buffer the content into a MemoryStream first, then Seek on the buffer.","Check stream.CanSeek before seeking and use a forward-only fallback."],"exampleFix":"// before\nstream.Seek (0, SeekOrigin.Begin);\n// after\nvar buffered = new MemoryStream ();\nstream.CopyTo (buffered);\nbuffered.Seek (0, SeekOrigin.Begin);","handlingStrategy":"validation","validationCode":"if (stream.CanSeek) stream.Seek (0, SeekOrigin.Begin);\nelse { /* buffer first or read forward */ }","typeGuard":"bool SupportsSeek (Stream s) => s.CanSeek;","tryCatchPattern":"try { stream.Seek (offset, origin); } catch (NotSupportedException) { /* fall back to forward read */ }","preventionTips":["Check CanSeek before any Seek or Position assignment.","Keep parsers for network/duplex streams strictly forward-only.","Copy to a seekable stream when reparse/retry semantics are needed."],"tags":["io","stream","not-supported","seek"],"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"}