dotnet/machinelearning · error · ArgumentException
Value name '{0}' matches an existing column name
Error message
Value name '{0}' matches an existing column name What it means
Thrown by DataFrame.Melt (or similar reshaping API) when the valueName you pass for the new melted values column already matches an existing column name in the DataFrame. The library requires all output column names of the reshape operation to be unique so the result schema is unambiguous.
Source
Thrown at src/Microsoft.Data.Analysis/DataFrame.cs:798
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));
}
}
foreach (var columnName in valueColumnList)
{
if (_columnCollection.IndexOf(columnName) < 0)View on GitHub (pinned to 7b76e69cf9)
Solutions
- Choose a valueName that does not already exist in the DataFrame
- Drop or rename the conflicting column before melting
- Catch ArgumentException and surface a clear message about the duplicate output column name
Example fix
// before
df.Melt(idColumns: new[] {"Date"}, valueColumns: new[] {"A","B"}, variableName: "Var", valueName: "A");
// after
df.Melt(idColumns: new[] {"Date"}, valueColumns: new[] {"A","B"}, variableName: "Var", valueName: "Value"); Defensive patterns
Strategy: validation
Validate before calling
if (df.Columns.Any(c => c.Name == valueName)) throw new InvalidOperationException($"Column '{valueName}' already exists; pick another valueName."); Try / catch
try { df.Melt(ids, values, varName, valueName); }
catch (ArgumentException ex) when (ex.ParamName == "valueName") { /* prompt for a different valueName */ } Prevention
- Uniqueness-check output names against df.Columns before any melt
- Avoid default names like 'Value' that commonly collide
- After drops/renames, re-derive the name list rather than caching it
When it happens
Trigger: Calling a DataFrame melt/reshape API whose valueName parameter collides with an existing column: _columnCollection.IndexOf(valueName) >= 0 inside the public DataFrame method at src/Microsoft.Data.Analysis/DataFrame.cs:798.
Common situations: Melting a wide table into long form where 'Values' or 'Value' already exists as a column; programmatic loops that reuse a default valueName without renaming prior columns; repeated melts on the same frame.
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
- {0} and {1} must be different
- string.Format(Strings.DuplicateColumnName, column.Name)
- Strings.DuplicateColumnName (formatted with column.Name)
- Strings.InvalidColumnName (formatted with columnName)
- Strings.BadColumnCast (formatted with column.DataType, typeo
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/96372030c7963abc.
Report an issue: GitHub.