dotnet/machinelearning · error · ArgumentNullException
Value cannot be null. (Parameter 'name')
Error message
Value cannot be null. (Parameter 'name')
What it means
DataViewSchema's string indexer looks up a column by name using an internal name map. Null or empty names are rejected with ArgumentNullException('name') before the lookup, since a null/empty column name can never exist in the schema.
Solutions
- Check string.IsNullOrEmpty(name) before indexing the schema
- Use GetColumnOrNull(name, out col) to safely probe for a column without throwing
- Fix the upstream source that produced a null/empty column name
Example fix
// before
var col = schema[name];
// after
if (!schema.GetColumnOrNull(name, out var col))
throw new ArgumentException($"Column '{name}' not found"); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(name)) throw new ArgumentException("Column name must be non-empty");
var col = schema[name]; Try / catch
try { var col = schema[name]; }
catch (ArgumentNullException ex) when (ex.ParamName == "name")
{ /* null/empty name — fix source of the name */ } Prevention
- Never pass user/config strings to the schema indexer without an IsNullOrEmpty check
- Prefer GetColumnOrNull for probing unknown column names
- Validate column names at configuration load time
When it happens
Trigger: Accessing schema[name] where name is null or the empty string, often from an unvalidated variable or an API that returned a null column name.
Common situations: Copy-pasting a variable name into the indexer instead of the literal; upstream code returning null column names; deserialization producing null metadata names.
Related errors
- Column ' ' not found (Parameter 'name')
- Value cannot be null. (Parameter 'type')
- argument should not be null.
- ArgumentNullException
- ArgumentNullException(nameof(column))
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/477037b3b24b2398.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.ML.DataView/DataViewSchema.cs:38
{
private readonly Column[] _columns;
private readonly Dictionary<string, int> _nameMap;
/// <summary>
/// Number of columns in the schema.
/// </summary>
public int Count => _columns.Length;
/// <summary>
/// Get the column by name. Throws an exception if such column does not exist.
/// Note that if multiple columns exist with the same name, the one with the biggest index is returned.
/// The other columns are considered 'hidden', and only accessible by their index.
/// </summary>
public Column this[string name]
{
get
{
if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name));
if (!_nameMap.TryGetValue(name, out int col))
throw new ArgumentOutOfRangeException(nameof(name), $"Column '{name}' not found");
return _columns[col];
}
}
/// <summary>
/// Get the column by index.
/// </summary>
public Column this[int columnIndex]
{
get
{
if (!(0 <= columnIndex && columnIndex < _columns.Length))
throw new ArgumentOutOfRangeException(nameof(columnIndex));
return _columns[columnIndex];
}
}View on GitHub (pinned to 7b76e69cf9)