{"record":{"id":"10b8de07c0ca04ed","repo":"jstedfast/MailKit","slug":"the-folder-does-not-support-partial-sorts","errorCode":null,"errorMessage":"The folder does not support partial sorts.","messagePattern":"The folder does not support partial sorts\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/MailFolder.cs","lineNumber":9256,"sourceCode":"\t\t/// </exception>\n\t\t/// <exception cref=\"CommandException\">\n\t\t/// The command failed.\n\t\t/// </exception>\n\t\tpublic virtual SearchResults Sort (SearchOptions options, SearchQuery query, IList<OrderBy> orderBy, PartialRange partialRange, CancellationToken cancellationToken = default)\n\t\t{\n\t\t\tif ((options & SearchOptions.All) != 0)\n\t\t\t\tthrow new ArgumentException (\"The SearchOptions.All flag cannot be combined with a partial range.\", nameof (options));\n\n\t\t\tif (query == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (query));\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\tthrow new NotSupportedException (\"The folder does not support partial sorts.\");\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Asynchronously sort messages matching the specified query, returning only the specified range of results.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// <para>Asynchronously searches the folder for messages matching the specified query, returning only the\n\t\t/// search results within the specified range in the specified sort order.</para>\n\t\t/// <para>Positive positions within the <paramref name=\"partialRange\"/> range are relative to the first result\n\t\t/// in the sort order while negative positions are relative to the last result. For example, a range of\n\t\t/// <c>1:50</c> will return the first 50 results in the specified sort order.</para>\n\t\t/// <note type=\"note\">If the range specified by <paramref name=\"partialRange\"/> references results beyond the end\n\t\t/// of the complete set of matching messages, then the results will only contain the unique identifiers that\n\t\t/// fall within the range (if any).</note>\n\t\t/// </remarks>\n\t\t/// <returns>The search results.</returns>\n\t\t/// <param name=\"options\">The search options.</param>\n\t\t/// <param name=\"query\">The search query.</param>","sourceCodeStart":9238,"sourceCodeEnd":9274,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/MailFolder.cs#L9238-L9274","documentation":"The base MailFolder.Sort overload (with PartialRange) throws NotSupportedException because partial sorts are only implemented by folder types/servers that support them (IMAP SORT with range support). The base virtual body always throws after its argument validation.","triggerScenarios":"Calling Sort(SearchOptions, SearchQuery, IList<OrderBy>, PartialRange, CancellationToken) on a folder whose implementation is the base stub, after query/orderBy/options validation passes.","commonSituations":"Server-side sorted, paged listings attempted against non-IMAP folders or servers lacking the sort capability.","solutions":["Use non-partial Sort(options, query, orderBy) and apply Skip/Take on the returned results.","Confirm the folder is an ImapFolder and the server advertises SORT support before using the partial overload.","Sort client-side: fetch summaries then order them with LINQ."],"exampleFix":"// before\nvar results = folder.Sort(SearchOptions.None, query, orderBy, partialRange);\n// after\nvar results = folder.Sort(SearchOptions.None, query, orderBy).Skip(0).Take(20).ToArray();","handlingStrategy":"try-catch","validationCode":"if (!(folder is ImapFolder))\n    useClientSideSort = true;","typeGuard":"bool supportsServerSort = folder is ImapFolder;","tryCatchPattern":"try {\n    results = folder.Sort(options, query, orderBy, partialRange);\n} catch (NotSupportedException) {\n    var uids = folder.Sort(options, query, orderBy);\n    results = uids.Skip(skip).Take(take).ToArray();\n}","preventionTips":["Gate partial sort behind an ImapFolder type check","Provide a client-side sort fallback path","Test against the actual server capabilities in integration tests"],"tags":["mailkit","not-supported","sort","partial-range"],"backgroundTag":"unsupported-operation","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}