dotnet/machinelearning · error · ArgumentNullException
name
Error message
name
What it means
The strongly-typed Builder.Add<TValue> validates that the column name is non-null and non-empty before adding the annotation/column entry; an empty string or null name is rejected with ArgumentNullException 'name'. Every column and annotation must have an identifying name.
Source
Thrown at src/Microsoft.ML.DataView/DataViewSchema.cs:298
{
if (selector(column.Name))
_items.Add((column.Name, column.Type, annotations.GetGetterInternal(column.Index), column.Annotations));
}
}
/// <summary>
/// Add one annotation column, strongly-typed version.
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="name">The annotation name.</param>
/// <param name="type">The annotation type.</param>
/// <param name="getter">The getter delegate.</param>
/// <param name="annotations">Annotations of the input column. Note that annotations on an annotation column is somewhat rare
/// except for certain types (for example, slot names for a vector, key values for something of key type).</param>
public void Add<TValue>(string name, DataViewType type, ValueGetter<TValue> getter, Annotations annotations = null)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException(nameof(name));
if (type == null)
throw new ArgumentNullException(nameof(type));
if (getter == null)
throw new ArgumentNullException(nameof(getter));
if (type.RawType != typeof(TValue))
throw new ArgumentException($"{nameof(type)}.{nameof(type.RawType)} must be of type '{typeof(TValue).FullName}'.", nameof(type));
_items.Add((name, type, getter, annotations));
}
/// <summary>
/// Add one annotation column, weakly-typed version.
/// </summary>
/// <param name="name">The annotation name.</param>
/// <param name="type">The annotation type.</param>
/// <param name="getter">The getter delegate that provides the value. Note that the type of the getter is still checked
/// inside this method.</param>
/// <param name="annotations">Annotations of the input column. Note that annotations on an annotation column is somewhat rareView on GitHub (pinned to 7b76e69cf9)
Solutions
- Validate the name string before calling Add (non-null, non-empty)
- Default to a meaningful name (e.g. the input column name) when the source value is blank
- Throw your own descriptive error earlier so the user sees which config field was blank
Example fix
// before
builder.Add(name, type, getter);
// after
if (string.IsNullOrEmpty(name))
throw new InvalidOperationException("Column name must be provided");
builder.Add(name, type, getter); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Column name required", nameof(name));
builder.Add(name, type, getter); Try / catch
try { builder.Add(name, type, getter); }
catch (ArgumentNullException e) when (e.ParamName == "name")
{
builder.Add(fallbackName ?? "Column0", type, getter);
} Prevention
- Validate user-supplied column-name config before building the schema
- Default missing names to a derived value (e.g. input column name)
- Never construct entries with string.Empty as a placeholder
When it happens
Trigger: Passing string.Empty as a name; passing a name variable that came from a failed lookup or split operation and is null; building output schema in a custom transform with placeholder names never filled in.
Common situations: Dynamically generated column names from feature/label configuration where the user left the setting blank; constructing slot-name or key-value annotations with empty kind strings.
Related errors
- type
- selector
- getter
- The provided model file {filePath} doesn't exist.
- Start must be called on a ModelLoader before it can be used.
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/25e3f43af25d3fd4.
Report an issue: GitHub.