dotnet/machinelearning · error · ArgumentException
Parameter must not be null, empty, or whitespace
Error message
Parameter must not be null, empty, or whitespace
What it means
Thrown by DataFrame.Melt when the variableName argument is null, empty, or whitespace. Melt reshapes wide data into long format and needs a valid name for the new 'variable' column it creates. The guard raises ArgumentException with Strings.ParameterMustNotBeNullOrWhitespace.
Source
Thrown at src/Microsoft.Data.Analysis/DataFrame.cs:743
/// // |----|-------|------|-------|
/// // | 1 | Alice | 2020 | 100 |
/// // | 2 | Bob | 2020 | 200 |
/// // | 1 | Alice | 2021 | 110 |
/// // | 2 | Bob | 2021 | 210 |
/// // | 1 | Alice | 2022 | 120 |
/// // | 2 | Bob | 2022 | 220 |
/// </code>
/// </example>
/// <remarks>
/// Note: The output rows are ordered by value column (all rows for the first value column,
/// then all rows for the second, etc.), which differs from pandas.melt() which orders by
/// source row.
/// </remarks>
public DataFrame Melt(IEnumerable<string> idColumns, IEnumerable<string> valueColumns = null, string variableName = "variable", string valueName = "value", bool dropNulls = false)
{
if (string.IsNullOrWhiteSpace(variableName))
{
throw new ArgumentException(Strings.ParameterMustNotBeNullOrWhitespace, nameof(variableName));
}
if (string.IsNullOrWhiteSpace(valueName))
{
throw new ArgumentException(Strings.ParameterMustNotBeNullOrWhitespace, nameof(valueName));
}
if (idColumns == null)
{
throw new ArgumentNullException(nameof(idColumns));
}
var idColumnList = idColumns.ToList();
HashSet<string> idColumnSet = null;
if (valueColumns is null)
{View on GitHub (pinned to 7b76e69cf9)
Solutions
- Pass a non-empty non-whitespace variableName, e.g. "variable"
- Omit the argument entirely to use the default value "variable"
- Trim/default the value at the call site if it comes from user input or config
Example fix
// before df.Melt(ids, values, variableName: ""); // after df.Melt(ids, values, variableName: "variable");
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(variableName)) variableName = "variable";
Try / catch
try { df.Melt(ids, values, variableName); }
catch (ArgumentException ex) when (ex.ParamName == "variableName") { /* supply default and retry */ } Prevention
- Rely on default parameter values instead of passing empty strings
- Sanitize config-driven names with string.IsNullOrWhiteSpace checks
- Validate names at config load time
When it happens
Trigger: Calling df.Melt(idColumns, valueColumns, variableName: "", ...) or with variableName: null or a whitespace string such as " ".
Common situations: Programmatically building melt arguments from config where an optional setting resolves to empty string; users forgetting that variableName has a default but explicitly passing empty to override it.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Value cannot be null. (Parameter 'idColumns')
- Must provide at least 1 ID column
- Must provide at least 1 value column when specifying value c
- Columns cannot exist in both idColumns and valueColumns
- There are no columns in the DataFrame to use as value column
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/240f1c6127a0bb35.
Report an issue: GitHub.