{"record":{"id":"a84800a2791ae638","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-name-imapfolder","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/Net/Imap/ImapFolder.cs","lineNumber":1850,"sourceCode":"\t\t\t// Note: if any folders returned in the LIST command are unparented, have the ImapEngine look up their\n\t\t\t// parent folders now so that they are not left in an inconsistent state.\n\t\t\tif (unparented)\n\t\t\t\tawait Engine.LookupParentFoldersAsync (list, cancellationToken).ConfigureAwait (false);\n\n\t\t\tif (status) {\n\t\t\t\tfor (int i = 0; i < children.Count; i++) {\n\t\t\t\t\tif (children[i].Exists)\n\t\t\t\t\t\tawait ((ImapFolder) children[i]).StatusAsync (items, false, cancellationToken).ConfigureAwait (false);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn children;\n\t\t}\n\n\t\tbool TryQueueGetSubfolderCommand (string name, CancellationToken cancellationToken, [NotNullWhen (true)] out ImapCommand? ic, [NotNullWhen (true)] out List<ImapFolder>? list, [NotNullWhen (true)] out string? fullName, [NotNullWhen (true)] out string? encodedName, out ImapFolder? folder)\n\t\t{\n\t\t\tif (name == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (name));\n\n\t\t\tif (!ImapEngine.IsValidMailboxName (name, DirectorySeparator))\n\t\t\t\tthrow new ArgumentException (\"The name of the subfolder is invalid.\", nameof (name));\n\n\t\t\tCheckState (false, false);\n\n\t\t\t// Any folder with a nil directory separator cannot have children.\n\t\t\tif (DirectorySeparator == '\\0') {\n\t\t\t\tencodedName = null;\n\t\t\t\tfullName = null;\n\t\t\t\tfolder = null;\n\t\t\t\tlist = null;\n\t\t\t\tic = null;\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfullName = FullName.Length > 0 ? FullName + DirectorySeparator + name : name;\n\t\t\tencodedName = Engine.EncodeMailboxName (fullName);","sourceCodeStart":1832,"sourceCodeEnd":1868,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolder.cs#L1832-L1868","documentation":"Guard in TryQueueGetSubfolderCommand within ImapFolder: the 'name' argument (the name/path of the subfolder to look up) was null. A subfolder name is required to build the command, so a null name is rejected with ArgumentNullException.","triggerScenarios":"Calling folder.GetSubfolder(null) or GetSubfolder(variable) where the variable is null (e.g. from unpopulated configuration or a LINQ result).","commonSituations":"Folder names read from config/DB rows that are NULL; deserialized models with missing name fields; string concatenation yielding null.","solutions":["Null-check or coalesce the name before calling GetSubfolder","Use string.IsNullOrEmpty validation on inputs sourced from config or persistence","Fix the upstream data source producing null names"],"exampleFix":"// before\nvar sub = folder.GetSubfolder(settings.ChildFolderName); // null -> throws\n// after\nif (string.IsNullOrEmpty(settings.ChildFolderName))\n    throw new InvalidOperationException(\"ChildFolderName is not configured\");\nvar sub = folder.GetSubfolder(settings.ChildFolderName);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name))\n    throw new ArgumentException(\"Subfolder name is required.\", nameof(name));\nvar sub = folder.GetSubfolder(name);","typeGuard":null,"tryCatchPattern":"try {\n    sub = folder.GetSubfolder(name);\n} catch (ArgumentNullException ex) when (ex.ParamName == \"name\") {\n    // name was null; fix upstream data source\n}","preventionTips":["Validate configured/persisted folder names at load time","Use non-nullable string types or null-checks before folder lookups","Fail fast with descriptive messages when config values are null"],"tags":["imap","mailkit","null-argument","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}