{"record":{"id":"34e242293e36fc80","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-requests","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'requests')","messagePattern":"Value cannot be null\\. \\(Parameter 'requests'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolder.cs","lineNumber":4603,"sourceCode":"\t\t/// <exception cref=\"ImapCommandException\">\n\t\t/// The server replied with a NO or BAD response.\n\t\t/// </exception>\n\t\tpublic override async Task<UniqueId?> AppendAsync (FormatOptions options, IAppendRequest request, CancellationToken cancellationToken = default)\n\t\t{\n\t\t\tvar ic = QueueAppendCommand (options, request, cancellationToken);\n\n\t\t\tawait Engine.RunAsync (ic).ConfigureAwait (false);\n\n\t\t\treturn ProcessAppendResponse (ic);\n\t\t}\n\n\t\tvoid ValidateArguments (FormatOptions options, IList<IAppendRequest> requests)\n\t\t{\n\t\t\tif (options == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (options));\n\n\t\t\tif (requests == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (requests));\n\n\t\t\tfor (int i = 0; i < requests.Count; i++) {\n\t\t\t\tif (requests[i] == null)\n\t\t\t\t\tthrow new ArgumentException (\"One or more of the requests is null.\");\n\n\t\t\t\tvar annotations = requests[i].Annotations;\n\t\t\t\tif (annotations != null && annotations.Count > 0 && (Engine.Capabilities & ImapCapabilities.Annotate) == 0)\n\t\t\t\t\tthrow new NotSupportedException (\"One ore more requests included annotations but the IMAP server does not support annotations.\");\n\t\t\t}\n\n\t\t\tCheckState (false, false);\n\t\t}\n\n\t\tImapCommand QueueMultiAppendCommand (FormatOptions options, IList<IAppendRequest> requests, CancellationToken cancellationToken)\n\t\t{\n\t\t\tvar format = CreateAppendOptions (options);\n\t\t\tvar builder = new StringBuilder (\"APPEND %F\");\n\t\t\tvar list = new List<object> {","sourceCodeStart":4585,"sourceCodeEnd":4621,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolder.cs#L4585-L4621","documentation":"ValidateArguments also requires a non-null requests list; a null list throws ArgumentNullException. Additionally, any null element inside the list throws ArgumentException ('One or more of the requests is null').","triggerScenarios":"Calling folder.Append(options, null), or passing a list that contains null IAppendRequest entries.","commonSituations":"Batching messages collected in a loop where some entries failed to build and were added as null; deserializing a request batch where items came back null.","solutions":["Pass a non-null List<IAppendRequest> containing only constructed AppendRequest items.","Filter nulls before calling: requests.RemoveAll(r => r == null) (or skip-and-log).","Check for null elements explicitly and report which batch item failed."],"exampleFix":"// before\nfolder.Append (options, requests);\n// after\nrequests.RemoveAll (r => r == null);\nif (requests.Count > 0)\n    folder.Append (options, requests);","handlingStrategy":"validation","validationCode":"if (requests == null || requests.Any (r => r == null)) throw new InvalidOperationException (\"requests list and all its items must be non-null\");","typeGuard":"bool IsValidBatch (IList<IAppendRequest> list) => list != null && list.All (r => r != null);","tryCatchPattern":"try { folder.Append (options, requests); } catch (ArgumentNullException ex) when (ex.ParamName == \"requests\") { /* supply non-null list */ } catch (ArgumentException ex) when (ex.Message.Contains (\"null\")) { requests.RemoveAll (r => r == null); folder.Append (options, requests); }","preventionTips":["Skip or log failed message builds instead of adding null to the batch","Validate batch contents before each Append call","Consider appending in a foreach loop so a single bad item doesn't invalidate the whole batch"],"tags":["imap","mailkit","null-argument","append","batch"],"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"}