jstedfast/MailKit · error · ArgumentNullException
Value cannot be null. (Parameter 'name')
Error message
Value cannot be null. (Parameter 'name')
What it means
MailKit's AccessControl(string name, IEnumerable<AccessRight> rights) constructor requires a non-null name identifying the IMAP user whose access rights are being set. When name is null, the constructor immediately throws ArgumentNullException(nameof(name)) at MailKit/AccessControl.cs:60. This fail-fast guard ensures an AccessControl object never exists without a named principal, since the name is written to the IMAP ACL command.
Solutions
- Pass a non-empty string for the name parameter (e.g. the IMAP user identifier) to the AccessControl constructor.
- Check the source of the name (config, dictionary lookup, server response) and ensure it is populated before constructing the AccessControl.
- If the name may legitimately be absent, guard the construction site with a null check and skip or log instead of constructing.
Example fix
// before
string user = aclLookup[folder]; // null when key missing
var ac = new AccessControl(user, rights);
// after
string user = aclLookup.TryGetValue(folder, out var u) ? u : null;
if (user == null)
throw new InvalidOperationException($"No ACL user found for folder {folder}");
var ac = new AccessControl(user, rights); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(name))
throw new ArgumentException("ACL user name must be non-empty", nameof(name));
var ac = new AccessControl(name, rights); Type guard
bool IsValidName(string name) => !string.IsNullOrEmpty(name);
Try / catch
try
{
var ac = new AccessControl(name, rights);
}
catch (ArgumentNullException ex) when (ex.ParamName == "name")
{
logger.LogError("ACL user name was null");
} Prevention
- Resolve the ACL user identifier before constructing AccessControl
- Validate config/dictionary-derived names for null/empty at load time
- Use string.IsNullOrWhiteSpace checks at construction sites
When it happens
Trigger: Calling new AccessControl(null, someAccessRightsEnumerable) — the first constructor argument is null (e.g. a variable holding the user name failed to initialize, or a lookup for the user identifier returned null).
Common situations: Building an IMAP ACL (SETACL/GETACL) payload where the user/login name came from a dictionary lookup, config value, or decoded server response that was null; copying a null Name from a deserialized AccessControl.
Related errors
- Value cannot be null. (Parameter 'rights')
- Value cannot be null. (Parameter 'array')
- Value cannot be null. (Parameter 'message')
- 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/bf40e777b4602900.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/AccessControl.cs:60
{
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.AccessControl"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="MailKit.AccessControl"/> with the given name and
/// access rights.
/// </remarks>
/// <param name="name">The identifier name.</param>
/// <param name="rights">The access rights.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="name"/> is <see langword="null" />.</para>
/// <para>-or-</para>
/// <para><paramref name="rights"/> is <see langword="null" />.</para>
/// </exception>
public AccessControl (string name, IEnumerable<AccessRight> rights)
{
if (name == null)
throw new ArgumentNullException (nameof (name));
Rights = new AccessRights (rights);
Name = name;
}
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.AccessControl"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="MailKit.AccessControl"/> with the given name and
/// access rights.
/// </remarks>
/// <param name="name">The identifier name.</param>
/// <param name="rights">The access rights.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="name"/> is <see langword="null" />.</para>
/// <para>-or-</para>
/// <para><paramref name="rights"/> is <see langword="null" />.</para>View on GitHub (pinned to 9d3859a785)