jstedfast/MailKit · error · ArgumentNullException
Value cannot be null. (Parameter 'rights')
Error message
Value cannot be null. (Parameter 'rights')
What it means
AccessRights.AddRange(string rights) parses a string of single-character access rights (e.g. "lrs") and adds each as an AccessRight. A null rights string throws ArgumentNullException(nameof(rights)) at MailKit/AccessRights.cs:160. The guard exists because there is no meaningful way to interpret a null rights specification.
Solutions
- Pass a valid rights string (e.g. "lrs") to AddRange.
- Ensure the code producing the rights string cannot return null; default to string.Empty when absent.
- Check the argument for null before calling AddRange and skip or substitute a default set.
Example fix
// before
string aclRights = GetRightsFromConfig(); // may be null
accessRights.AddRange(aclRights);
// after
string aclRights = GetRightsFromConfig() ?? string.Empty;
if (aclRights.Length > 0)
accessRights.AddRange(aclRights); Defensive patterns
Strategy: validation
Validate before calling
if (rights != null)
accessRights.AddRange(rights); Type guard
bool HasRights(string rights) => !string.IsNullOrEmpty(rights);
Try / catch
try
{
accessRights.AddRange(rights);
}
catch (ArgumentNullException ex) when (ex.ParamName == "rights")
{
logger.LogWarning("No rights string available; using empty rights");
} Prevention
- Default rights strings from config/server responses with ?? string.Empty
- Validate parsed ACL tokens for null before adding
- Treat missing rights as an explicit empty set rather than null
When it happens
Trigger: Calling rights.AddRange(null) with the string overload — e.g. a null string from a parsed server response, config value, or an uninitialized variable.
Common situations: Building IMAP ACL rights from a decoded GETACL response where the rights token was missing; passing a settings value that was never configured.
Related errors
- Value cannot be null. (Parameter 'name')
- 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/0126e2054f38119a.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/AccessRights.cs:160
public bool Add (char right)
{
return Add (new AccessRight (right));
}
/// <summary>
/// Add the rights specified by the characters in the given string.
/// </summary>
/// <remarks>
/// Adds the rights specified by the characters in the given string.
/// </remarks>
/// <param name="rights">The rights.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="rights"/> is <see langword="null" />.
/// </exception>
public void AddRange (string rights)
{
if (rights == null)
throw new ArgumentNullException (nameof (rights));
for (int i = 0; i < rights.Length; i++)
Add (new AccessRight (rights[i]));
}
/// <summary>
/// Add the range of specified rights.
/// </summary>
/// <remarks>
/// Adds the range of specified rights.
/// </remarks>
/// <param name="rights">The rights.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="rights"/> is <see langword="null" />.
/// </exception>
public void AddRange (IEnumerable<AccessRight> rights)
{
if (rights == null)View on GitHub (pinned to 9d3859a785)