{"record":{"id":"64aa38fd6fba9f16","repo":"jstedfast/MailKit","slug":"one-or-more-of-the-requests-is-null","errorCode":null,"errorMessage":"One or more of the requests is null.","messagePattern":"One or more of the requests is null\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolder.cs","lineNumber":4607,"sourceCode":"\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> {\n\t\t\t\tthis\n\t\t\t};\n\n\t\t\tfor (int i = 0; i < requests.Count; i++) {","sourceCodeStart":4589,"sourceCodeEnd":4625,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolder.cs#L4589-L4625","documentation":"ImapFolder.SetAnnotations/annotation APIs validate every entry in the requests list before queueing commands. If any element of the IList<IAnnotationRequest> is null, an ArgumentException is thrown. This is fail-fast argument validation so no partial IMAP work is issued.","triggerScenarios":"Calling an annotations API (e.g. SetAnnotations/Store with annotation requests) passing a list where one or more elements are null, e.g. new IAnnotationRequest[] { request1, null }.","commonSituations":"Building request arrays dynamically and appending null from failed lookups; deserializing request lists from config/JSON where entries are missing; LINQ Select that returns null for some items.","solutions":["Inspect the requests list before calling and remove/replace any null elements","Ensure the code that creates each request object actually instantiates it (no null returns)","If entries are optional, filter them: requests.RemoveAll(r => r == null) or requests.Where(r => r != null)","Wrap the call in try/catch (ArgumentException) and report which list index was null"],"exampleFix":"// before\nvar requests = new List<IAnnotationRequest> { getRequest(id) }; // getRequest may return null\nfolder.SetAnnotations(requests);\n// after\nvar requests = new List<IAnnotationRequest> { getRequest(id) ?? throw new InvalidOperationException(\"no annotation request for \" + id) };\nfolder.SetAnnotations(requests);","handlingStrategy":"validation","validationCode":"if (requests == null || requests.Any(r => r == null))\n    throw new InvalidOperationException(\"all annotation requests must be non-null\");","typeGuard":"bool AllNonNull<T>(IEnumerable<T> items) => items != null && !items.Any(i => i is null);","tryCatchPattern":"try { folder.SetAnnotations(requests); }\ncatch (ArgumentException ex) { log.LogError(ex, \"Null annotation request in list\"); }","preventionTips":["Validate list contents at construction time","Avoid factories that return null; use exceptions or Result types","Use nullable-reference-analysis warnings to catch null flow"],"tags":["imap","argument-validation","null-reference","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"}