jstedfast/MailKit · warning · ArgumentNullException
Value cannot be null. (Parameter 'message')
Error message
Value cannot be null. (Parameter 'message')
What it means
The AlertEventArgs constructor stores the IMAP alert message and throws ArgumentNullException(nameof(message)) at MailKit/AlertEventArgs.cs:53 when message is null. This is an internal MailKit type used to surface server ALERT responses; the message text is the whole point of the event, so a null is rejected.
Solutions
- If constructing manually, pass a non-empty string message.
- If this surfaces from MailKit internals, check the server's untagged ALERT response — it is sending an empty message; report/patch the server behavior.
- Wrap event subscription/processing in try-catch if a non-conformant server is involved and cannot be fixed.
Example fix
// before var args = new AlertEventArgs(serverAlertText); // null for empty ALERT // after var args = new AlertEventArgs(string.IsNullOrEmpty(serverAlertText) ? "(empty alert)" : serverAlertText);
Defensive patterns
Strategy: try-catch
Validate before calling
if (!string.IsNullOrEmpty(serverAlertText))
OnAlert(new AlertEventArgs(serverAlertText)); Type guard
bool HasAlertText(string msg) => !string.IsNullOrEmpty(msg);
Try / catch
try
{
ProcessAlert(new AlertEventArgs(message));
}
catch (ArgumentNullException ex) when (ex.ParamName == "message")
{
logger.LogWarning("Server sent an ALERT with no message text");
} Prevention
- Coerce empty server ALERT text to a placeholder string before constructing args
- When hitting this from MailKit internals, investigate the server's untagged ALERT responses
- Guard any code that constructs event args directly from protocol data
When it happens
Trigger: Calling new AlertEventArgs(null) — normally only reachable from MailKit's own protocol handling when a server sends an untagged ALERT response with a null/empty text, or from test/user code constructing the args manually.
Common situations: A misbehaving or non-conformant IMAP server emitting an ALERT with no text; user code constructing AlertEventArgs directly in tests or custom protocol layers.
Related errors
- Value cannot be null. (Parameter 'name')
- Value cannot be null. (Parameter 'rights')
- Value cannot be null. (Parameter 'array')
- Value cannot be null. (Parameter 'entry')
- Value cannot be null. (Parameter 'specifier')
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/faada321cf7601e5.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/AlertEventArgs.cs:53
/// <see cref="MailKit.Net.Imap.ImapClient"/>, will emit Alert
/// events when they receive alert messages from the server.
/// </remarks>
public class AlertEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.AlertEventArgs"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="AlertEventArgs"/>.
/// </remarks>
/// <param name="message">The alert message.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="message"/> is <see langword="null" />.
/// </exception>
public AlertEventArgs (string message)
{
if (message == null)
throw new ArgumentNullException (nameof (message));
Message = message;
}
/// <summary>
/// Gets the alert message.
/// </summary>
/// <remarks>
/// The alert message will be the exact message received from the server.
/// </remarks>
/// <value>The alert message.</value>
public string Message {
get; private set;
}
}
}
View on GitHub (pinned to 9d3859a785)