jstedfast/MailKit · error · ArgumentException
One or more of the requests is null.
Error message
One or more of the requests is null.
What it means
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.
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
Example fix
// before
var requests = new List<IAnnotationRequest> { getRequest(id) }; // getRequest may return null
folder.SetAnnotations(requests);
// after
var requests = new List<IAnnotationRequest> { getRequest(id) ?? throw new InvalidOperationException("no annotation request for " + id) };
folder.SetAnnotations(requests); Defensive patterns
Strategy: validation
Validate before calling
if (requests == null || requests.Any(r => r == null))
throw new InvalidOperationException("all annotation requests must be non-null"); Type guard
bool AllNonNull<T>(IEnumerable<T> items) => items != null && !items.Any(i => i is null);
Try / catch
try { folder.SetAnnotations(requests); }
catch (ArgumentException ex) { log.LogError(ex, "Null annotation request in list"); } Prevention
- 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
When it happens
Trigger: 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 }.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- array
- bodyParts
- Cannot rename a folder using itself as the new parent…
- Cannot search for an empty set of unique identifiers.
- Cannot search for an invalid unique identifier.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/64aa38fd6fba9f16.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Net/Imap/ImapFolder.cs:4607
{
var ic = QueueAppendCommand (options, request, cancellationToken);
await Engine.RunAsync (ic).ConfigureAwait (false);
return ProcessAppendResponse (ic);
}
void ValidateArguments (FormatOptions options, IList<IAppendRequest> requests)
{
if (options == null)
throw new ArgumentNullException (nameof (options));
if (requests == null)
throw new ArgumentNullException (nameof (requests));
for (int i = 0; i < requests.Count; i++) {
if (requests[i] == null)
throw new ArgumentException ("One or more of the requests is null.");
var annotations = requests[i].Annotations;
if (annotations != null && annotations.Count > 0 && (Engine.Capabilities & ImapCapabilities.Annotate) == 0)
throw new NotSupportedException ("One ore more requests included annotations but the IMAP server does not support annotations.");
}
CheckState (false, false);
}
ImapCommand QueueMultiAppendCommand (FormatOptions options, IList<IAppendRequest> requests, CancellationToken cancellationToken)
{
var format = CreateAppendOptions (options);
var builder = new StringBuilder ("APPEND %F");
var list = new List<object> {
this
};
for (int i = 0; i < requests.Count; i++) {View on GitHub (pinned to 9d3859a785)