dotnet/machinelearning · error · ArgumentException
Variable name ' ' matches an existing column name
Error message
Variable name '{0}' matches an existing column name What it means
Thrown by DataFrame.Melt when the variableName matches a column name already present in the DataFrame, since melt would create a duplicate 'variable' column. Raised as ArgumentException (Strings.VariableNameAlreadyExists, formatted with the name) on 'variableName'.
Solutions
- Choose a variableName that does not collide with any existing column (e.g. "attribute")
- Rename or drop the conflicting column before melting
- Check _columns.IndexOf(variableName) < 0 before calling Melt
Example fix
// before df.Melt(ids, values, variableName: "Sales"); // 'Sales' column exists // after df.Melt(ids, values, variableName: "Metric");
Defensive patterns
Strategy: validation
Validate before calling
if (df.Columns.IndexOf(variableName) >= 0) variableName = variableName + "_melt";
Type guard
bool IsFreeName(DataFrame df, string name) => df.Columns.IndexOf(name) < 0;
Try / catch
try { df.Melt(ids, values, variableName); }
catch (ArgumentException ex) when (ex.ParamName == "variableName") { /* pick a non-colliding name and retry */ } Prevention
- Generate output names with a suffix or prefix to avoid schema collisions
- Check column names before re-melting already-melted frames
- Reserve the variable/value names in your schema naming convention
When it happens
Trigger: Calling df.Melt(ids, values, variableName: "Sales") when a column named 'Sales' already exists; using the default "variable" while the DataFrame already has a 'variable' column (e.g. re-melting an already-melted frame).
Common situations: Running melt twice on the same DataFrame in a pipeline; name collisions with measurement columns; config-supplied names that clash with the schema.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Columns cannot exist in both idColumns and valueColumns
- Must provide at least 1 ID column
- Must provide at least 1 value column when specifying value…
- Parameter must not be null, empty, or whitespace
- There are no columns in the DataFrame to use as value…
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/32fdb764852edaad.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.Data.Analysis/DataFrame.cs:793
if (valueColumns != null && valueColumnList.Count == 0)
{
throw new ArgumentException(Strings.MissingValueColumns, nameof(valueColumns));
}
if (valueColumns != null && valueColumnList.Any(v => idColumnList.Contains(v)))
{
throw new ArgumentException(Strings.DuplicateColumnsInIdAndValueLists, nameof(valueColumns));
}
if (valueColumns == null && valueColumnList.Count == 0)
{
throw new InvalidOperationException(Strings.NoValueColumnsRemaining);
}
if (_columnCollection.IndexOf(variableName) >= 0)
{
throw new ArgumentException(string.Format(Strings.VariableNameAlreadyExists, variableName), nameof(variableName));
}
if (_columnCollection.IndexOf(valueName) >= 0)
{
throw new ArgumentException(string.Format(Strings.ValueNameAlreadyExists, valueName), nameof(valueName));
}
if (string.Equals(variableName, valueName))
{
throw new ArgumentException(string.Format(Strings.VariableNameAndValueNameMustBeDifferent, nameof(variableName), nameof(valueName)), nameof(valueName));
}
foreach (var columnName in idColumnList)
{
if (_columnCollection.IndexOf(columnName) < 0)
{
throw new ArgumentException(string.Format(Strings.InvalidColumnName, columnName), nameof(idColumns));
}View on GitHub (pinned to 7b76e69cf9)