jstedfast/MailKit · error · ArgumentNullException
ArgumentNullException
Error message
ArgumentNullException
What it means
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).
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.
Example fix
// before folder.Append(null, messages, flags); // after folder.Append(FormatOptions.Default, messages, flags);
Defensive patterns
Strategy: validation
Validate before calling
options ??= FormatOptions.Default; folder.Append(options, messages, flags);
Type guard
FormatOptions EnsureOptions(FormatOptions? o) => o ?? FormatOptions.Default;
Try / catch
try { folder.Append(options, messages, flags); } catch (ArgumentNullException ex) { /* ex.ParamName == "options": fix option source */ } Prevention
- Always pass FormatOptions.Default rather than null
- Initialize shared options objects once at startup
- Type nullable options parameters as FormatOptions? and coalesce
When it happens
Trigger: Calling folder.Append(null, messages, flags) where options was expected from a cached/shared variable that was never initialized.
Common situations: 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.
Related errors
- part
- ArgumentOutOfRangeException
- One or more of the messages is null.
- The number of messages and the number of flags must be…
- The uid is invalid.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/afcc5fa74d76dde4.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/IMailFolderAppendExtensions.cs:935
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// Internationalized formatting was requested but is not supported by the server.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="CommandException">
/// The command failed.
/// </exception>
public static IList<UniqueId> Append (this IMailFolder folder, FormatOptions options, IList<MimeMessage> messages, IList<MessageFlags> flags, CancellationToken cancellationToken = default, ITransferProgress? progress = null)
{
if (options == null)
throw new ArgumentNullException (nameof (options));
if (messages == null)
throw new ArgumentNullException (nameof (messages));
for (int i = 0; i < messages.Count; i++) {
if (messages[i] == null)
throw new ArgumentException ("One or more of the messages is null.");
}
if (flags == null)
throw new ArgumentNullException (nameof (flags));
if (messages.Count != flags.Count)
throw new ArgumentException ("The number of messages and the number of flags must be equal.");
var requests = new AppendRequest[messages.Count];
for (int i = 0; i < messages.Count; i++) {
requests[i] = new AppendRequest (messages[i], flags[i]) {View on GitHub (pinned to 9d3859a785)