{"record":{"id":"bf40e777b4602900","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-name","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'name')","messagePattern":"Value cannot be null\\. \\(Parameter 'name'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/AccessControl.cs","lineNumber":60,"sourceCode":"\t{\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.AccessControl\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"MailKit.AccessControl\"/> with the given name and\n\t\t/// access rights.\n\t\t/// </remarks>\n\t\t/// <param name=\"name\">The identifier name.</param>\n\t\t/// <param name=\"rights\">The access rights.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <para><paramref name=\"name\"/> is <see langword=\"null\" />.</para>\n\t\t/// <para>-or-</para>\n\t\t/// <para><paramref name=\"rights\"/> is <see langword=\"null\" />.</para>\n\t\t/// </exception>\n\t\tpublic AccessControl (string name, IEnumerable<AccessRight> rights)\n\t\t{\n\t\t\tif (name == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (name));\n\n\t\t\tRights = new AccessRights (rights);\n\t\t\tName = name;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.AccessControl\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"MailKit.AccessControl\"/> with the given name and\n\t\t/// access rights.\n\t\t/// </remarks>\n\t\t/// <param name=\"name\">The identifier name.</param>\n\t\t/// <param name=\"rights\">The access rights.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <para><paramref name=\"name\"/> is <see langword=\"null\" />.</para>\n\t\t/// <para>-or-</para>\n\t\t/// <para><paramref name=\"rights\"/> is <see langword=\"null\" />.</para>","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AccessControl.cs#L42-L78","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nstring user = aclLookup[folder]; // null when key missing\nvar ac = new AccessControl(user, rights);\n\n// after\nstring user = aclLookup.TryGetValue(folder, out var u) ? u : null;\nif (user == null)\n    throw new InvalidOperationException($\"No ACL user found for folder {folder}\");\nvar ac = new AccessControl(user, rights);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name))\n    throw new ArgumentException(\"ACL user name must be non-empty\", nameof(name));\nvar ac = new AccessControl(name, rights);","typeGuard":"bool IsValidName(string name) => !string.IsNullOrEmpty(name);","tryCatchPattern":"try\n{\n    var ac = new AccessControl(name, rights);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"name\")\n{\n    logger.LogError(\"ACL user name was null\");\n}","preventionTips":["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"],"tags":["argument-null","imap","acl","mailkit"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}