{"record":{"id":"4f503e5329e80473","repo":"dotnet/machinelearning","slug":"columns-cannot-exist-in-both-idcolumns-and-valueco","errorCode":null,"errorMessage":"Columns cannot exist in both idColumns and valueColumns","messagePattern":"Columns cannot exist in both idColumns and valueColumns","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrame.cs","lineNumber":783,"sourceCode":"            var valueColumnList = valueColumns?.ToList()\n                ?? _columnCollection\n                    .Where(c => !idColumnSet.Contains(c.Name))\n                    .Select(c => c.Name)\n                    .ToList();\n\n            if (idColumnList.Count == 0)\n            {\n                throw new ArgumentException(Strings.MissingIdColumns, nameof(idColumns));\n            }\n\n            if (valueColumns != null && valueColumnList.Count == 0)\n            {\n                throw new ArgumentException(Strings.MissingValueColumns, nameof(valueColumns));\n            }\n\n            if (valueColumns != null && valueColumnList.Any(v => idColumnList.Contains(v)))\n            {\n                throw new ArgumentException(Strings.DuplicateColumnsInIdAndValueLists, nameof(valueColumns));\n            }\n\n            if (valueColumns == null && valueColumnList.Count == 0)\n            {\n                throw new InvalidOperationException(Strings.NoValueColumnsRemaining);\n            }\n\n            if (_columnCollection.IndexOf(variableName) >= 0)\n            {\n                throw new ArgumentException(string.Format(Strings.VariableNameAlreadyExists, variableName), nameof(variableName));\n            }\n\n            if (_columnCollection.IndexOf(valueName) >= 0)\n            {\n                throw new ArgumentException(string.Format(Strings.ValueNameAlreadyExists, valueName), nameof(valueName));\n            }\n\n            if (string.Equals(variableName, valueName))","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrame.cs#L765-L801","documentation":"Thrown by DataFrame.Melt when a column name appears in both idColumns and valueColumns. A column cannot simultaneously be kept as an identifier and melted as a value; the library rejects the overlap with ArgumentException (Strings.DuplicateColumnsInIdAndValueLists) on 'valueColumns'.","triggerScenarios":"Calling df.Melt(new[]{\"Id\",\"Sales\"}, new[]{\"Sales\"}) — any name present in both lists; usually from overlapping user selections or generated lists without deduplication.","commonSituations":"Dynamic dashboards where users multi-select columns for both groups; building the lists from overlapping queries; copy-paste errors in hardcoded lists.","solutions":["Remove the duplicated names from valueColumns (or idColumns) so the lists are disjoint","Compute valueColumns as the set difference of the desired columns and idColumns","Deduplicate/intersect-check the two lists before calling Melt"],"exampleFix":"// before\ndf.Melt(new[] { \"Id\", \"Sales\" }, new[] { \"Sales\", \"Cost\" });\n// after\ndf.Melt(new[] { \"Id\" }, new[] { \"Sales\", \"Cost\" });","handlingStrategy":"validation","validationCode":"var dupes = valueColumnList.Intersect(idColumnList).ToList();\nif (dupes.Any()) throw new InvalidOperationException($\"In both lists: {string.Join(\",\", dupes)}\");","typeGuard":null,"tryCatchPattern":"try { df.Melt(ids, values); }\ncatch (ArgumentException ex) when (ex.ParamName == \"valueColumns\" && ex.Message.Contains(\"both\")) { /* deduplicate and retry */ }","preventionTips":["Compute valueColumns as set difference from idColumns","Use HashSet-based selection so lists stay disjoint","Add a pre-call intersection check in pipelines"],"tags":["dotnet","dataframe","melt","conflict"],"backgroundTag":"conflicting-config-options","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}