{"record":{"id":"3f6358a0575872e6","repo":"Unity-Technologies/UnityCsReference","slug":"duplicate-column-indices-are-not-allowed","errorCode":null,"errorMessage":"Duplicate column indices are not allowed","messagePattern":"Duplicate column indices are not allowed","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/MultiColumnHeader.cs","lineNumber":84,"sourceCode":"            m_HeaderButtonsControlID = GUIUtility.GetPermanentControlID();\n        }\n\n        public void SetSortingColumns(int[] columnIndices, bool[] sortAscending)\n        {\n            if (columnIndices == null)\n                throw new ArgumentNullException(\"columnIndices\");\n\n            if (sortAscending == null)\n                throw new ArgumentNullException(\"sortAscending\");\n\n            if (columnIndices.Length != sortAscending.Length)\n                throw new ArgumentException(\"Input arrays should have same length\");\n\n            if (columnIndices.Length > state.maximumNumberOfSortedColumns)\n                throw new ArgumentException(\"The maximum number of sorted columns is \" + state.maximumNumberOfSortedColumns + \". Trying to set \" + columnIndices.Length + \" columns.\");\n\n            if (columnIndices.Length != columnIndices.DistinctCount())\n                throw new ArgumentException(\"Duplicate column indices are not allowed\", \"columnIndices\");\n\n            bool changed = false;\n\n            if (!columnIndices.AsSpan().SequenceEqual(state.sortedColumns))\n            {\n                state.sortedColumns = columnIndices;\n                changed = true;\n            }\n\n            for (int i = 0; i < columnIndices.Length; ++i)\n            {\n                var column = GetColumn(columnIndices[i]);\n                if (column.sortedAscending != sortAscending[i])\n                {\n                    column.sortedAscending = sortAscending[i];\n                    changed = true;\n                }\n            }","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/MultiColumnHeader.cs#L66-L102","documentation":"Thrown by SetSortingColumns when columnIndices contains duplicate values. Sorting by the same column twice is meaningless and would produce ambiguous sort order, so duplicates are rejected.","triggerScenarios":"Passing an array like {0, 0, 1}; merging sort lists from multiple sources without deduplication.","commonSituations":"Aggregating user sort selections across UI panels without dedup; restored state from a buggy serializer that duplicated entries.","solutions":["Deduplicate columnIndices preserving order before calling (e.g. Distinct()).","Validate columnIndices.DistinctCount() == columnIndices.Length as a precondition.","Fix the upstream source that introduced the duplicate."],"exampleFix":"// before\nheader.SetSortingColumns(cols, flags); // cols has dupes\n\n// after\nvar deduped = cols.Distinct().ToArray();\nheader.SetSortingColumns(deduped, flags.Take(deduped.Length).ToArray());","handlingStrategy":"validation","validationCode":"var distinct = columnIndices.Distinct().ToArray(); if (distinct.Length != columnIndices.Length) { /* handle duplicate */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate sort column sources before calling.","Use a HashSet during construction to prevent duplicates.","Validate distinctness when restoring persisted sort state."],"tags":["unity-editor","treeview","multicolumn","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}