{"record":{"id":"4b33c6cdb53e536d","repo":"jstedfast/MailKit","slug":"section","errorCode":null,"errorMessage":"section","messagePattern":"section","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolderFetch.cs","lineNumber":4517,"sourceCode":"\t\t\tif (!TryQueueGetStreamCommand (index, offset, count, cancellationToken, progress, out var ic, out var ctx))\n\t\t\t\treturn new MemoryStream ();\n\n\t\t\ttry {\n\t\t\t\tawait Engine.RunAsync (ic).ConfigureAwait (false);\n\n\t\t\t\treturn ProcessGetStreamResponse (ic, ctx, index);\n\t\t\t} finally {\n\t\t\t\tctx.Dispose ();\n\t\t\t}\n\t\t}\n\n\t\tImapCommand QueueGetStreamCommand (UniqueId uid, string section, CancellationToken cancellationToken, ITransferProgress? progress, out FetchStreamContext ctx)\n\t\t{\n\t\t\tif (!uid.IsValid)\n\t\t\t\tthrow new ArgumentException (\"The uid is invalid.\", nameof (uid));\n\n\t\t\tif (section == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (section));\n\n\t\t\tCheckState (true, false);\n\n\t\t\tvar command = string.Format (\"UID FETCH {0} (BODY.PEEK[{1}])\\r\\n\", uid, section);\n\t\t\tvar ic = new ImapCommand (Engine, cancellationToken, this, command);\n\t\t\tic.RegisterUntaggedHandler (\"FETCH\", FetchStreamHandler);\n\t\t\tic.UserData = ctx = new FetchStreamContext (progress);\n\n\t\t\tEngine.QueueCommand (ic);\n\n\t\t\treturn ic;\n\t\t}\n\n\t\tStream ProcessGetStreamResponse (ImapCommand ic, FetchStreamContext ctx, UniqueId uid, string section)\n\t\t{\n\t\t\tProcessFetchResponse (ic);\n\n\t\t\tif (!ctx.TryGetSection (uid, section, out var s, true))","sourceCodeStart":4499,"sourceCodeEnd":4535,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolderFetch.cs#L4499-L4535","documentation":"QueueGetStreamCommand throws ArgumentNullException when the section string passed to a stream-fetch API is null. The section identifies the MIME body part / specifier embedded in the IMAP 'BODY.PEEK[section]' command, so null would produce a malformed command. Empty or malformed section values are forwarded to the server, but null is rejected locally.","triggerScenarios":"Calling ImapFolder.GetStream(uid, null, ...) or GetStreamAsync / GetStream(index, null, ...) where the section argument is a null string — typically because a part-path-to-section conversion returned null or a variable was never set.","commonSituations":"Building the section string conditionally and leaving it null when a body part is not found; passing the result of a lookup into GetStream without a null check; confusing the index overload's whole-message semantics with the uid overload that requires a value.","solutions":["Pass a valid section string: \"\" for the whole message or \"1.1\" for a MIME part.","Null-check the section before calling: if (section == null) use \"\" or throw/log.","Use BodyPart.PartSpecifier from a prior body-structure fetch to build the section value.","If you want the entire message, call GetMessage or GetStream with an empty string rather than null."],"exampleFix":"// before\nvar stream = folder.GetStream(uid, section); // section is null\n// after\nvar stream = folder.GetStream(uid, section ?? string.Empty);","handlingStrategy":"validation","validationCode":"if (section == null)\n    section = string.Empty; // whole message\nvar stream = folder.GetStream(uid, section);","typeGuard":null,"tryCatchPattern":"try {\n    var stream = folder.GetStream(uid, section);\n} catch (ArgumentNullException) {\n    stream = folder.GetStream(uid, string.Empty);\n}","preventionTips":["Use empty string, not null, for the full-message section.","Derive section specifiers from fetched BodyPart objects.","Null-check nullable section inputs at your API boundary.","Avoid hand-building section strings from conditionally-set variables."],"tags":["imap","mailkit","null-argument","bodypart"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}