{"record":{"id":"54dbdfe772b41d27","repo":"jstedfast/MailKit","slug":"null-smtpstream","errorCode":null,"errorMessage":"null","messagePattern":"null","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Smtp/SmtpStream.cs","lineNumber":193,"sourceCode":"\t\t/// Get or set the position within the current stream.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Gets or sets the position within the current stream.\n\t\t/// </remarks>\n\t\t/// <returns>The current position within the stream.</returns>\n\t\t/// <value>The position of the stream.</value>\n\t\t/// <exception cref=\"System.IO.IOException\">\n\t\t/// An I/O error occurred.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.NotSupportedException\">\n\t\t/// The stream does not support seeking.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ObjectDisposedException\">\n\t\t/// The stream has been disposed.\n\t\t/// </exception>\n\t\tpublic override long Position {\n\t\t\tget { return Stream.Position; }\n\t\t\tset { throw new NotSupportedException (); }\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Get the length of the stream, in bytes.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Gets the length of the stream, in bytes.\n\t\t/// </remarks>\n\t\t/// <returns>A long value representing the length of the stream in bytes.</returns>\n\t\t/// <value>The length of the stream.</value>\n\t\t/// <exception cref=\"System.NotSupportedException\">\n\t\t/// The stream does not support seeking.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ObjectDisposedException\">\n\t\t/// The stream has been disposed.\n\t\t/// </exception>\n\t\tpublic override long Length {\n\t\t\tget { return Stream.Length; }","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Smtp/SmtpStream.cs#L175-L211","documentation":"SmtpStream.Position setter unconditionally throws NotSupportedException: the SMTP protocol stream is sequential and cannot be seeked. The getter delegates to the underlying stream, but setting Position (or calling Seek) makes no sense for a protocol stream that reads server responses in order.","triggerScenarios":"Assigning to stream.Position on a SmtpStream obtained from SmtpClient, e.g. generic stream-copy or retry logic that assumes a seekable Stream.","commonSituations":"Passing the client's internal stream to utilities that rewind streams; code shared between FileStream and network streams assuming CanSeek.","solutions":["Do not set Position on SmtpStream; treat it as a forward-only stream","Check stream.CanSeek before seeking and handle non-seekable streams","Buffer data yourself if you need re-reads"],"exampleFix":"// before\nsmtpStream.Position = 0;\n// after\nif (smtpStream.CanSeek)\n    smtpStream.Position = 0;\nelse\n    throw new InvalidOperationException(\"SmtpStream is not seekable\");","handlingStrategy":"type-guard","validationCode":"if (stream.CanSeek) { /* safe */ }","typeGuard":"bool IsSeekable(Stream s) => s.CanSeek;","tryCatchPattern":"try { stream.Position = 0; }\ncatch (NotSupportedException) { /* copy to seekable stream */ }","preventionTips":["Check CanSeek before Position/Seek","Treat MailKit protocol streams as forward-only","Buffer into MemoryStream when random access is needed"],"tags":["smtp","mailkit","stream","not-supported"],"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"}