jstedfast/MailKit · error · ArgumentNullException
Value cannot be null. (Parameter 'keywords')
Error message
Value cannot be null. (Parameter 'keywords')
What it means
The MessageFlagsChangedEventArgs(int index, MessageFlags flags, IReadOnlySetOfStrings keywords) constructor requires a non-null keywords set. ArgumentNullException is thrown when keywords is null. Pass an empty set instead when there are no keywords.
Solutions
- Pass an empty set (e.g. new HashSet<string>() as IReadOnlySetOfStrings) instead of null
- Check upstream data and default null keywords to an empty collection before constructing the args
- In library internals, report the null to the MailKit maintainers with a stack trace
Example fix
// before new MessageFlagsChangedEventArgs(index, flags, null); // after var keywords = (IReadOnlySetOfStrings)(rawKeywords ?? new HashSet<string>()); new MessageFlagsChangedEventArgs(index, flags, keywords);
Defensive patterns
Strategy: validation
Validate before calling
if (keywords == null) keywords = new HashSet<string>(); var args = new MessageFlagsChangedEventArgs(index, flags, keywords);
Type guard
IReadOnlySetOfStrings NonNull(IReadOnlySetOfStrings set) => set ?? new HashSet<string>();
Try / catch
try { args = new MessageFlagsChangedEventArgs(index, flags, keywords); }
catch (ArgumentNullException ex) when (ex.ParamName == "keywords") { args = new MessageFlagsChangedEventArgs(index, flags, new HashSet<string>()); } Prevention
- Treat 'no keywords' as an empty set, never null
- Coalesce nullable collections at event-construction boundaries
- Initialize keyword collections in constructors of your folder wrappers
When it happens
Trigger: Raising or constructing MessageFlagsChangedEventArgs manually (e.g. in custom folder implementations or tests) with keywords = null.
Common situations: Implementing a custom IMailFolder or proxy that forwards flag-change notifications but passes through a null keywords collection from upstream code.
Related errors
- Value cannot be null. (Parameter 'labels')
- Specified argument was out of the range of valid values…
- A metadata tag identifier cannot be empty.
- ArgumentNullException
- ArgumentOutOfRangeException
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/ff3bdba13037521a.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/MessageFlagsChangedEventArgs.cs:89
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.MessageFlagsChangedEventArgs"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="MessageFlagsChangedEventArgs"/>.
/// </remarks>
/// <param name="index">The message index.</param>
/// <param name="flags">The message flags.</param>
/// <param name="keywords">The user-defined keywords.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="keywords"/> is <see langword="null" />.
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="index"/> is out of range.
/// </exception>
public MessageFlagsChangedEventArgs (int index, MessageFlags flags, IReadOnlySetOfStrings keywords) : base (index)
{
if (keywords == null)
throw new ArgumentNullException (nameof (keywords));
Keywords = keywords;
Flags = flags;
}
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.MessageFlagsChangedEventArgs"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="MessageFlagsChangedEventArgs"/>.
/// </remarks>
/// <param name="index">The message index.</param>
/// <param name="flags">The message flags.</param>
/// <param name="modseq">The modification sequence value.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="index"/> is out of range.
/// </exception>
public MessageFlagsChangedEventArgs (int index, MessageFlags flags, ulong modseq) : base (index)View on GitHub (pinned to 9d3859a785)