{"record":{"id":"afcc5fa74d76dde4","repo":"jstedfast/MailKit","slug":"argumentnullexception-imailfolderappendextensions","errorCode":null,"errorMessage":"ArgumentNullException","messagePattern":"ArgumentNullException","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/IMailFolderAppendExtensions.cs","lineNumber":935,"sourceCode":"\t\t/// <exception cref=\"System.OperationCanceledException\">\n\t\t/// The operation was canceled via the cancellation token.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.NotSupportedException\">\n\t\t/// Internationalized formatting was requested but is not supported by the server.\n\t\t/// </exception>\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=\"ProtocolException\">\n\t\t/// The server's response contained unexpected tokens.\n\t\t/// </exception>\n\t\t/// <exception cref=\"CommandException\">\n\t\t/// The command failed.\n\t\t/// </exception>\n\t\tpublic static IList<UniqueId> Append (this IMailFolder folder, FormatOptions options, IList<MimeMessage> messages, IList<MessageFlags> flags, CancellationToken cancellationToken = default, ITransferProgress? progress = null)\n\t\t{\n\t\t\tif (options == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (options));\n\n\t\t\tif (messages == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (messages));\n\n\t\t\tfor (int i = 0; i < messages.Count; i++) {\n\t\t\t\tif (messages[i] == null)\n\t\t\t\t\tthrow new ArgumentException (\"One or more of the messages is null.\");\n\t\t\t}\n\n\t\t\tif (flags == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (flags));\n\n\t\t\tif (messages.Count != flags.Count)\n\t\t\t\tthrow new ArgumentException (\"The number of messages and the number of flags must be equal.\");\n\n\t\t\tvar requests = new AppendRequest[messages.Count];\n\t\t\tfor (int i = 0; i < messages.Count; i++) {\n\t\t\t\trequests[i] = new AppendRequest (messages[i], flags[i]) {","sourceCodeStart":917,"sourceCodeEnd":953,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/IMailFolderAppendExtensions.cs#L917-L953","documentation":"IMailFolder.Append (extension) validates its parameters before touching the server. Passing a null FormatOptions throws ArgumentNullException because the options object controls message formatting and must always be supplied (or explicitly defaulted).","triggerScenarios":"Calling folder.Append(null, messages, flags) where options was expected from a cached/shared variable that was never initialized.","commonSituations":"Refactors that introduced an options parameter but left call sites passing null; helper wrappers forwarding an optional options value that defaulted to null instead of FormatOptions.Default.","solutions":["Pass FormatOptions.Default instead of null.","Coalesce null options at the call site: options ?? FormatOptions.Default.","Fix the wrapper/helper that forwards a null options value."],"exampleFix":"// before\nfolder.Append(null, messages, flags);\n// after\nfolder.Append(FormatOptions.Default, messages, flags);","handlingStrategy":"validation","validationCode":"options ??= FormatOptions.Default;\nfolder.Append(options, messages, flags);","typeGuard":"FormatOptions EnsureOptions(FormatOptions? o) => o ?? FormatOptions.Default;","tryCatchPattern":"try { folder.Append(options, messages, flags); } catch (ArgumentNullException ex) { /* ex.ParamName == \"options\": fix option source */ }","preventionTips":["Always pass FormatOptions.Default rather than null","Initialize shared options objects once at startup","Type nullable options parameters as FormatOptions? and coalesce"],"tags":["null-argument","mailkit","csharp","argument-validation"],"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"}