{"record":{"id":"10cc86edad8d9118","repo":"jstedfast/MailKit","slug":"partspecifier-imapfolderfetch","errorCode":null,"errorMessage":"partSpecifier","messagePattern":"partSpecifier","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolderFetch.cs","lineNumber":3056,"sourceCode":"\n\t\t\ttry {\n\t\t\t\tawait Engine.RunAsync (ic).ConfigureAwait (false);\n\n\t\t\t\tvar stream = ProcessGetHeadersResponse (ic, ctx, index);\n\n\t\t\t\treturn await ParseHeadersAsync (stream, cancellationToken).ConfigureAwait (false);\n\t\t\t} finally {\n\t\t\t\tctx.Dispose ();\n\t\t\t}\n\t\t}\n\n\t\tImapCommand QueueGetHeadersCommand (int index, string partSpecifier, CancellationToken cancellationToken, ITransferProgress? progress, out FetchStreamContext ctx, out string[] tags)\n\t\t{\n\t\t\tif (index < 0 || index >= Count)\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (index));\n\n\t\t\tif (partSpecifier == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (partSpecifier));\n\n\t\t\tCheckState (true, false);\n\n\t\t\tvar command = string.Format (\"FETCH {0} ({1})\\r\\n\", index + 1, GetBodyPartQuery (partSpecifier, true, out tags));\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 ProcessGetHeadersResponse (ImapCommand ic, FetchStreamContext ctx, int index, string[] tags)\n\t\t{\n\t\t\tProcessFetchResponse (ic);\n\n\t\t\tif (!ctx.TryGetSection (index, tags[0], out var section, true))","sourceCodeStart":3038,"sourceCodeEnd":3074,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolderFetch.cs#L3038-L3074","documentation":"ArgumentNullException whose Message is the parameter name \"partSpecifier\", thrown by QueueGetHeadersCommand when GetHeaders(int index, ...) is called with a null part specifier. A non-null specifier (e.g., \"1\", \"1.2\", \"TEXT\") is required to build the FETCH BODY[part.HEADER] query.","triggerScenarios":"Passing null as partSpecifier to GetHeaders(int index, string partSpecifier, ...) — commonly when a BodyPart lookup returned null upstream and the specifier was derived as bodyPart?.PartSpecifier.","commonSituations":"Chaining `folder.GetBodyPart(...)` results that failed silently; refactored code dropping the default \"1\" specifier; deserialized BodyPart objects with null PartSpecifier.","solutions":["Pass a concrete specifier such as \"1\" (the top-level MIME part) or the BodyPart.PartSpecifier from a fresh GetBodyParts call.","Add a null check on the specifier (or the BodyPart it came from) before the call.","Use the GetHeaders(int index) overload without a specifier when you want the full message headers."],"exampleFix":"// before\nvar headers = folder.GetHeaders(index, bodyPart?.PartSpecifier);\n\n// after\nif (bodyPart == null)\n    bodyPart = (BodyPartMultipart)folder.GetBodyParts(index);\nvar headers = folder.GetHeaders(index, bodyPart.PartSpecifier);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(partSpecifier))\n    throw new InvalidOperationException(\"A body part specifier (e.g. \\\"1\\\" or \\\"1.2\\\") is required.\");","typeGuard":"bool HasSpecifier(BodyPart? part) => !string.IsNullOrEmpty(part?.PartSpecifier);","tryCatchPattern":"try { var headers = folder.GetHeaders(index, partSpecifier); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"partSpecifier\") { /* default to \"1\" or re-fetch structure */ }","preventionTips":["Default missing specifiers to \"1\" (top-level part) when full-message headers are acceptable.","Null-check BodyPart results before using PartSpecifier.","Use the parameterless GetHeaders(index) overload when no specific part is needed."],"tags":["imap","null-argument","mailkit","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-16T04:17:20.429Z"}