dotnet/machinelearning · error · ArgumentException
{0} and {1} must be different
Error message
{0} and {1} must be different What it means
Thrown by a public DataFrame reshaping method when variableName and valueName are the same string. The two output columns produced by the melt must have distinct names, so the library rejects identical names up front with Strings.VariableNameAndValueNameMustBeDifferent.
Source
Thrown at src/Microsoft.Data.Analysis/DataFrame.cs:803
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)
{
throw new ArgumentException(string.Format(Strings.InvalidColumnName, columnName), nameof(valueColumns));
}
}
View on GitHub (pinned to 7b76e69cf9)
Solutions
- Pass distinct strings for variableName and valueName
- Validate the two names differ before calling the API (string.Equals check)
- Catch ArgumentException and prompt the user for a different name
Example fix
// before
df.Melt(new[] {"Date"}, new[] {"A"}, variableName: "Column", valueName: "Column");
// after
df.Melt(new[] {"Date"}, new[] {"A"}, variableName: "Column", valueName: "Value"); Defensive patterns
Strategy: validation
Validate before calling
if (string.Equals(variableName, valueName)) throw new ArgumentException("variableName and valueName must differ."); Try / catch
try { df.Melt(ids, values, varName, valueName); }
catch (ArgumentException ex) when (ex.ParamName == "valueName") { /* fix duplicate output names */ } Prevention
- Never bind both output-name parameters to the same source value
- Centralize melt calls behind a helper that enforces distinct names
- Add a unit test covering the rename-melt path with user-supplied names
When it happens
Trigger: Calling DataFrame.Melt (src/Microsoft.Data.Analysis/DataFrame.cs:803) with variableName == valueName, e.g. both set to "Key" or both to a user-supplied single string.
Common situations: Binding both output-name parameters to the same config value or user input; copy-paste where one of the two names was not changed; dynamic name generation that returns the same string for both.
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
- Value name '{0}' matches an existing column name
- 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/35c2fd8ee1580361.
Report an issue: GitHub.