jstedfast/MailKit · error · ArgumentException
No indexes were specified.
Error message
No indexes were specified.
What it means
ImapUtils.FormatIndexSet builds IMAP message-sequence sets and throws an ArgumentNullException if indexes is null and an ArgumentException if the list is empty. An IMAP sequence set cannot be formed from zero indexes, so the library refuses early rather than emitting an invalid command.
Solutions
- Check indexes != null && indexes.Count > 0 before calling the API and skip the call when empty.
- Guard by folder Count: only fetch ranges when folder.Count > 0.
- When indexes come from a search, handle the empty result as a no-op instead of a fetch.
Example fix
// before
var messages = await folder.GetMessagesAsync(searchResults, summary);
// after
if (searchResults == null || searchResults.Count == 0)
return new List<IMessageSummary>();
var messages = await folder.GetMessagesAsync(searchResults, summary); Defensive patterns
Strategy: validation
Validate before calling
if (indexes == null || indexes.Count == 0)
return; // nothing to fetch — treat as no-op Prevention
- Always check collection Count before index/UID-based MailKit calls
- Treat empty search results as an early return, not a fetch
- Never pass through nullable lists without a null check
When it happens
Trigger: Calling methods like folder.GetMessages(IList<int>, ...), AddFlags/RemoveFlags with an index list, or StoreAsync with UniqueIds where the passed IList<int>/uint list is empty (e.g. no messages matched a previous query).
Common situations: Passing the result of a filtered search straight into GetMessages without checking Count; using message count of an empty folder; downstream code produced an empty ID list.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Cannot search for an empty set of unique identifiers.
- The uid is invalid.
- offset
- count
- No sort order provided.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/58b7ebc081035c99.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Net/Imap/ImapUtils.cs:274
/// <para>-or-</para>
/// <para><paramref name="indexes"/> is <see langword="null" />.</para>
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// One or more of the indexes has a negative value.
/// </exception>
public static void FormatIndexSet (ImapEngine engine, StringBuilder builder, IList<int> indexes)
{
if (engine == null)
throw new ArgumentNullException (nameof (engine));
if (builder == null)
throw new ArgumentNullException (nameof (builder));
if (indexes == null)
throw new ArgumentNullException (nameof (indexes));
if (indexes.Count == 0)
throw new ArgumentException ("No indexes were specified.", nameof (indexes));
int index = 0;
while (index < indexes.Count) {
if (indexes[index] < 0)
throw new ArgumentException ("One or more of the indexes is negative.", nameof (indexes));
int begin = indexes[index];
int end = indexes[index];
int i = index + 1;
if (i < indexes.Count) {
if (indexes[i] == end + 1) {
end = indexes[i++];
while (i < indexes.Count && indexes[i] == end + 1) {
end++;
i++;View on GitHub (pinned to 9d3859a785)