jstedfast/MailKit · error · ArgumentException

One or more messages is missing information needed for…

Error message

One or more messages is missing information needed for sorting.

What it means

MessageSorter.Sort throws ArgumentException when one of the supplied IMessageSummary items lacks the MessageSummaryFields required by the chosen sort criteria. IMessageSummary objects are fetched with a field mask; if e.g. OrderBy.Date is requested but the summaries were fetched without Envelope/Flags/Size fields, the sorter cannot read the values it needs to compare.

Solutions

  1. Re-fetch the summaries with the required fields, e.g. `folder.Fetch(0, -1, MessageSummaryFields.Envelope | MessageSummaryFields.Flags | MessageSummaryFields.Size)`.
  2. Compute the required fields and OR them into the fetch mask before fetching.
  3. If refetching is too costly, restrict the sort criteria to fields you already have.
  4. Verify that (summary.Fields & requiredFields) == requiredFields for each item before calling Sort.

Example fix

// before
var items = folder.Fetch(0, -1, MessageSummaryFields.Flags);
var sorted = items.Sort(new List<OrderBy> { OrderBy.Date }); // needs Envelope
// after
var items = folder.Fetch(0, -1, MessageSummaryFields.Envelope | MessageSummaryFields.Flags);
var sorted = items.Sort(new List<OrderBy> { OrderBy.Date });
Defensive patterns

Strategy: validation

Validate before calling

var required = MessageSummaryFields.Envelope | MessageSummaryFields.Flags;
if (items.Any(m => (m.Fields & required) != required))
    items = folder.Fetch(0, -1, required);
var sorted = items.Sort(new List<OrderBy> { OrderBy.Date });

Type guard

bool HasRequiredFields(IMessageSummary m, MessageSummaryFields required) => (m.Fields & required) == required;

Try / catch

try {
    return items.Sort(orderBy);
} catch (ArgumentException ex) when (ex.Message.Contains("missing information")) {
    items = folder.Fetch(0, -1, MessageSummaryFields.Envelope | MessageSummaryFields.Flags | MessageSummaryFields.Size);
    return items.Sort(orderBy);
}

Prevention

When it happens

Trigger: Calling `messages.Sort(new List<OrderBy> { OrderBy.DisplayFrom })` with summaries fetched via IMailFolder.Fetch(..., MessageSummaryFields.Flags) — i.e. fields mask not including Envelope — or fetching with an empty/minimal MessageSummaryItems and later applying a sort that needs those fields.

Common situations: Fetching summaries with MessageSummaryFields.None or a minimal mask in one code path, then sorting with criteria (From/To/Subject/Date) that require the Envelope field in another; changing sort columns at runtime without re-fetching the summaries with the extra fields; caching IMessageSummary objects fetched long ago with a narrower mask.

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


AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15). Data as JSON: /api/errors/cb1d31091c665287. Report an issue: GitHub.

Appendix: source

Thrown at MailKit/MessageSorter.cs:234

		/// <para><paramref name="orderBy"/> is an empty list.</para>
		/// </exception>
		public static IList<T> Sort<T> (this IEnumerable<T> messages, IList<OrderBy> orderBy) where T : IMessageSummary
		{
			if (messages == null)
				throw new ArgumentNullException (nameof (messages));

			if (orderBy == null)
				throw new ArgumentNullException (nameof (orderBy));

			if (orderBy.Count == 0)
				throw new ArgumentException ("No sort order provided.", nameof (orderBy));

			var requiredFields = GetMessageSummaryItems (orderBy);
			var list = new List<T> ();

			foreach (var message in messages) {
				if ((message.Fields & requiredFields) != requiredFields)
					throw new ArgumentException ("One or more messages is missing information needed for sorting.", nameof (messages));

				list.Add (message);
			}

			if (list.Count < 2)
				return list;

			var comparer = new MessageComparer<T> (orderBy);

			list.Sort (comparer);

			return list;
		}

		/// <summary>
		/// Sorts the messages by the specified ordering.
		/// </summary>
		/// <remarks>

View on GitHub (pinned to 9d3859a785)