{"record":{"id":"f561ba899e5feefb","repo":"jstedfast/MailKit","slug":"the-number-of-messages-and-the-number-of-dates-must-be-equal","errorCode":null,"errorMessage":"The number of messages and the number of dates must be equal.","messagePattern":"The number of messages and the number of dates must be equal\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/IMailFolderAppendExtensions.cs","lineNumber":1126,"sourceCode":"\t\t\tif (messages == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (messages));\n\n\t\t\tfor (int i = 0; i < messages.Count; i++) {\n\t\t\t\tif (messages[i] == null)\n\t\t\t\t\tthrow new ArgumentException (\"One or more of the messages is null.\");\n\t\t\t}\n\n\t\t\tif (flags == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (flags));\n\n\t\t\tif (messages.Count != flags.Count)\n\t\t\t\tthrow new ArgumentException (\"The number of messages and the number of flags must be equal.\");\n\n\t\t\tif (dates == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (dates));\n\n\t\t\tif (messages.Count != dates.Count)\n\t\t\t\tthrow new ArgumentException (\"The number of messages and the number of dates must be equal.\");\n\n\t\t\tvar requests = new AppendRequest[messages.Count];\n\t\t\tfor (int i = 0; i < messages.Count; i++) {\n\t\t\t\trequests[i] = new AppendRequest (messages[i], flags[i], dates[i]) {\n\t\t\t\t\tTransferProgress = progress\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn folder.Append (options, requests, cancellationToken);\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Asynchronously append the specified messages to the folder.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Asynchronously appends the specified messages to the folder and returns the UniqueIds assigned to the messages.\n\t\t/// </remarks>\n\t\t/// <returns>The UIDs of the appended messages, if available; otherwise an empty array.</returns>","sourceCodeStart":1108,"sourceCodeEnd":1144,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/IMailFolderAppendExtensions.cs#L1108-L1144","documentation":"Append also accepts per-message internal dates and validates that dates.Count equals messages.Count, since each AppendRequest carries one DateTimeOffset. A mismatch throws this ArgumentException after the flags checks pass.","triggerScenarios":"Calling the Append overload with dates where dates.Count != messages.Count — e.g. dates for a subset, or a single date reused for all.","commonSituations":"Reconstructing messages with original IMAP internal dates but collecting dates only for messages that had a Date header; mismatched batch sizes between messages and dates pipelines.","solutions":["Derive dates from the same collection: messages.Select (m => m.Date).ToList ().","If a uniform date is fine, use messages.Count copies of that DateTimeOffset.","Use the Append overload without dates (server assigns current time) if internal dates are not needed."],"exampleFix":"// before\nfolder.Append (messages, flags, datesForSomeMessages);\n\n// after\nvar dates = messages.Select (m => m.Date).ToList ();\nfolder.Append (messages, flags, dates);","handlingStrategy":"validation","validationCode":"if (dates == null || dates.Count != messages.Count)\n    dates = messages.Select (m => m.Date.DateTime).ToList ();","typeGuard":null,"tryCatchPattern":"try {\n    folder.Append (messages, flags, dates);\n} catch (ArgumentException ex) when (ex.Message.Contains (\"number of dates\")) {\n    logger.LogError (ex, \"dates count {0} != messages count {1}\", dates?.Count, messages?.Count);\n}","preventionTips":["Derive per-message dates from the MimeMessage objects themselves.","Drop the dates argument entirely if server timestamps suffice.","Pair messages/flags/dates into one list of tuples so they cannot diverge."],"tags":["argument-validation","collection-mismatch","imap-append","mailkit"],"backgroundTag":"invalid-argument-value","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}