dotnet/machinelearning · error · ArgumentException

input cannot be empty (Parameter 'input')

Error message

input cannot be empty (Parameter 'input')

What it means

Utils.Normalize throws ArgumentException with message 'input cannot be empty' when given the empty string, because an empty string cannot become a valid C# identifier. Note the loop earlier prefixes '_' only for inputs starting with non-letter characters (digits can't yield ""), so empty input falls straight into the switch case.

Source

Thrown at src/Microsoft.ML.CodeGenerator/Utils.cs:143

                var f = val as bool?;
                return f.GetValueOrDefault() ? "true" : "false";
            }

            return val.ToString();
        }

        internal static string Normalize(string input)
        {
            //check if first character is int
            if (!string.IsNullOrEmpty(input) && int.TryParse(input.Substring(0, 1), out int val))
            {
                input = "_" + input;
                return Normalize(input);
            }
            switch (input)
            {
                case null: throw new ArgumentNullException(nameof(input));
                case "": throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input));
                default:
                    var sanitizedInput = Sanitize(input);
                    return sanitizedInput.First().ToString().ToUpper() + sanitizedInput.Substring(1);
            }
        }

        internal static Type GetCSharpType(DataKind labelType)
        {
            switch (labelType)
            {
                case Microsoft.ML.Data.DataKind.String:
                    return typeof(string);
                case Microsoft.ML.Data.DataKind.Boolean:
                    return typeof(bool);
                case Microsoft.ML.Data.DataKind.Single:
                    return typeof(float);
                case Microsoft.ML.Data.DataKind.Double:
                    return typeof(double);

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Validate the name is non-empty (and not just whitespace) before invoking code generation.
  2. Provide a default/fallback identifier when the source name is empty.
  3. Fix the data source headers so no column has a blank name.
  4. Catch ArgumentException and substitute a placeholder like "Column1".

Example fix

// before
var identifier = Utils.Normalize(header);
// after
if (string.IsNullOrWhiteSpace(header)) header = "Column" + i;
var identifier = Utils.Normalize(header);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(header))
    header = "Column" + index; // assign fallback before Normalize
var identifier = Utils.Normalize(header);

Type guard

static bool IsNonEmptyName(string s) => !string.IsNullOrWhiteSpace(s);

Try / catch

try
{
    identifier = Utils.Normalize(header);
}
catch (ArgumentException ex) when (ex.ParamName == "input")
{
    identifier = "Column_" + index;
}

Prevention

When it happens

Trigger: Calling Utils.Normalize("") directly, or passing a PipelineNode/schema item whose name is the empty string (e.g. a column with a blank header or an empty name field) through the code generation path.

Common situations: CSV/TSV files with an empty header cell; whitespace-only headers that get trimmed to empty elsewhere; manually constructed metadata with empty names.

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


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/bc9ac072b055c2ed. Report an issue: GitHub.