{"record":{"id":"cb1d31091c665287","repo":"jstedfast/MailKit","slug":"one-or-more-messages-is-missing-information-needed-for","errorCode":null,"errorMessage":"One or more messages is missing information needed for sorting.","messagePattern":"One or more messages is missing information needed for sorting\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/MessageSorter.cs","lineNumber":234,"sourceCode":"\t\t/// <para><paramref name=\"orderBy\"/> is an empty list.</para>\n\t\t/// </exception>\n\t\tpublic static IList<T> Sort<T> (this IEnumerable<T> messages, IList<OrderBy> orderBy) where T : IMessageSummary\n\t\t{\n\t\t\tif (messages == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (messages));\n\n\t\t\tif (orderBy == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (orderBy));\n\n\t\t\tif (orderBy.Count == 0)\n\t\t\t\tthrow new ArgumentException (\"No sort order provided.\", nameof (orderBy));\n\n\t\t\tvar requiredFields = GetMessageSummaryItems (orderBy);\n\t\t\tvar list = new List<T> ();\n\n\t\t\tforeach (var message in messages) {\n\t\t\t\tif ((message.Fields & requiredFields) != requiredFields)\n\t\t\t\t\tthrow new ArgumentException (\"One or more messages is missing information needed for sorting.\", nameof (messages));\n\n\t\t\t\tlist.Add (message);\n\t\t\t}\n\n\t\t\tif (list.Count < 2)\n\t\t\t\treturn list;\n\n\t\t\tvar comparer = new MessageComparer<T> (orderBy);\n\n\t\t\tlist.Sort (comparer);\n\n\t\t\treturn list;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Sorts the messages by the specified ordering.\n\t\t/// </summary>\n\t\t/// <remarks>","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/MessageSorter.cs#L216-L252","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-fetch the summaries with the required fields, e.g. `folder.Fetch(0, -1, MessageSummaryFields.Envelope | MessageSummaryFields.Flags | MessageSummaryFields.Size)`.","Compute the required fields and OR them into the fetch mask before fetching.","If refetching is too costly, restrict the sort criteria to fields you already have.","Verify that (summary.Fields & requiredFields) == requiredFields for each item before calling Sort."],"exampleFix":"// before\nvar items = folder.Fetch(0, -1, MessageSummaryFields.Flags);\nvar sorted = items.Sort(new List<OrderBy> { OrderBy.Date }); // needs Envelope\n// after\nvar items = folder.Fetch(0, -1, MessageSummaryFields.Envelope | MessageSummaryFields.Flags);\nvar sorted = items.Sort(new List<OrderBy> { OrderBy.Date });","handlingStrategy":"validation","validationCode":"var required = MessageSummaryFields.Envelope | MessageSummaryFields.Flags;\nif (items.Any(m => (m.Fields & required) != required))\n    items = folder.Fetch(0, -1, required);\nvar sorted = items.Sort(new List<OrderBy> { OrderBy.Date });","typeGuard":"bool HasRequiredFields(IMessageSummary m, MessageSummaryFields required) => (m.Fields & required) == required;","tryCatchPattern":"try {\n    return items.Sort(orderBy);\n} catch (ArgumentException ex) when (ex.Message.Contains(\"missing information\")) {\n    items = folder.Fetch(0, -1, MessageSummaryFields.Envelope | MessageSummaryFields.Flags | MessageSummaryFields.Size);\n    return items.Sort(orderBy);\n}","preventionTips":["Pick the fetch field mask based on the sort criteria you plan to use, not the other way around.","Keep MessageSummaryFields.Envelope in the fetch mask by default for sorting/threading scenarios.","Don't mix summaries from fetch calls with different masks in one list."],"tags":["csharp","mailkit","sorting","imessagesummary","fetch-fields"],"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-15T23:17:13.987Z"}