{"record":{"id":"179af8425db02846","repo":"jstedfast/MailKit","slug":"no-sort-order-provided-messagethreader","errorCode":null,"errorMessage":"No sort order provided.","messagePattern":"No sort order provided\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/MessageThreader.cs","lineNumber":452,"sourceCode":"\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentOutOfRangeException\">\n\t\t/// <paramref name=\"algorithm\"/> is not a valid threading algorithm.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentException\">\n\t\t/// <para><paramref name=\"messages\"/> contains one or more items that is missing information needed for threading or sorting.</para>\n\t\t/// <para>-or-</para>\n\t\t/// <para><paramref name=\"orderBy\"/> is an empty list.</para>\n\t\t/// </exception>\n\t\tpublic static IList<MessageThread> Thread (this IEnumerable<IMessageSummary> messages, ThreadingAlgorithm algorithm, IList<OrderBy> orderBy)\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\tswitch (algorithm) {\n\t\t\tcase ThreadingAlgorithm.OrderedSubject: return ThreadBySubject (messages, orderBy);\n\t\t\tcase ThreadingAlgorithm.References: return ThreadByReferences (messages, orderBy);\n\t\t\tdefault: throw new ArgumentOutOfRangeException (nameof (algorithm));\n\t\t\t}\n\t\t}\n\n\t\tstatic bool IsForward (string subject, int index)\n\t\t{\n\t\t\treturn (subject[index] == 'F' || subject[index] == 'f') &&\n\t\t\t\t(subject[index + 1] == 'W' || subject[index + 1] == 'w') &&\n\t\t\t\t(subject[index + 2] == 'D' || subject[index + 2] == 'd') &&\n\t\t\t\tsubject[index + 3] == ':';\n\t\t}\n\n\t\tstatic bool IsReply (string subject, int index)\n\t\t{","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/MessageThreader.cs#L434-L470","documentation":"MessageThreader.Thread throws this ArgumentException when the orderBy list of OrderBy clauses is non-null but empty. Threading requires at least one sort criterion to order messages within threads, so an empty collection is rejected up front.","triggerScenarios":"Calling MessageThreader.Thread(messages, algorithm, orderBy) with a valid (non-null) but zero-element IList<OrderBy>, e.g. `new List<OrderBy>()` or a filtered list that ended up empty.","commonSituations":"Building the sort-order list dynamically from user preferences or config where no sort keys were selected; copy-pasting a Thread call from sample code and deleting the OrderBy items; deserializing sort settings from an empty JSON array.","solutions":["Pass at least one OrderBy value, e.g. new List<OrderBy> { OrderBy.Date }","If the list is built dynamically, validate Count > 0 before calling Thread and choose a sensible default sort","Check that config/serialization of the sort preferences actually produced entries"],"exampleFix":"// before\nvar orderBy = new List<OrderBy>();\nvar tree = threader.Thread(messages, ThreadingAlgorithm.References, orderBy);\n// after\nvar orderBy = new List<OrderBy> { OrderBy.Date, OrderBy.Subject };\nvar tree = threader.Thread(messages, ThreadingAlgorithm.References, orderBy);","handlingStrategy":"validation","validationCode":"if (orderBy == null || orderBy.Count == 0)\n\torderBy = new List<OrderBy> { OrderBy.Date }; // or throw earlier with context","typeGuard":"bool HasSortOrder(IList<OrderBy> orderBy) => orderBy != null && orderBy.Count > 0;","tryCatchPattern":"try {\n\ttree = threader.Thread(messages, algorithm, orderBy);\n} catch (ArgumentException ex) when (ex.ParamName == \"orderBy\") {\n\t// fall back to a default sort or skip threading\n}","preventionTips":["Validate the OrderBy list has Count > 0 before calling Thread","Provide a default sort order when preferences are empty","Centralize threading behind a helper that enforces a fallback sort"],"tags":["argument-validation","mailkit","threading","empty-collection"],"backgroundTag":"empty-required-field","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"}