dotnet/machinelearning · error · ArgumentNullException
Value cannot be null. (Parameter 'type')
Error message
Value cannot be null. (Parameter 'type')
What it means
DataViewSchema.Column requires a non-null DataViewType; passing null for 'type' throws ArgumentNullException naming 'type'. The type object defines the column's data type and raw representation, so it is mandatory.
Source
Thrown at src/Microsoft.ML.DataView/DataViewSchema.cs:115
/// </summary>
public DataViewType Type { get; }
/// <summary>
/// The annotations of the column.
/// </summary>
public Annotations Annotations { get; }
internal Column(string name, int index, bool isHidden, DataViewType type, Annotations annotations)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException(nameof(name));
if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index));
Name = name;
Index = index;
IsHidden = isHidden;
Type = type ?? throw new ArgumentNullException(nameof(type));
Annotations = annotations ?? Annotations.Empty;
}
public override string ToString()
{
var annotationsString = (Annotations == null || Annotations.Schema.Count == 0) ?
null : $" {{{string.Join(", ", Annotations.Schema.Select(x => x.Name))}}}";
return $"{Name}: {Type}{annotationsString}";
}
}
/// <summary>
/// This class represents the schema of one column of a data view, without an attachment to a particular <see cref="DataViewSchema"/>.
/// </summary>
public struct DetachedColumn
{
/// <summary>
/// The name of the column.View on GitHub (pinned to 7b76e69cf9)
Solutions
- Ensure a concrete DataViewType (e.g. NumberType.R4, TextType, BooleanDataViewType) is passed; fix the null-producing factory/mapping.
- Add an explicit fallback default type for unmapped source types instead of returning null.
- Fail fast upstream with a clear message when type inference cannot determine a type.
- Prefer builder APIs that compute the type from data rather than passing a raw type argument.
Example fix
// before DataViewType t = typeMap[sourceKind]; // may return null var column = new Column(name, index, false, t, null); // after DataViewType t = typeMap.TryGetValue(sourceKind, out var mapped) ? mapped : NumberType.R4; var column = new Column(name, index, false, t, null);
Defensive patterns
Strategy: validation
Validate before calling
if (type == null) throw new ArgumentException("Column type must be resolved before schema construction"); Type guard
bool HasType(DataViewType t) => t != null;
Prevention
- Ensure type maps have entries for every source type
- Fail at the mapping site with a clear message instead of returning null
When it happens
Trigger: Constructing a Column (or Builder.Add overload) with type == null — e.g. type inference failed upstream, a variable was never assigned, or a factory method returned null for an unsupported data kind.
Common situations: Type-mapping tables missing an entry for a source column type (returning null); loading metadata from files where a type declaration is absent; calling constructors directly instead of builder APIs that infer types.
Related errors
- Specified argument was out of the range of valid values. (Pa
- Value cannot be null. (Parameter 'idColumns')
- ArgumentNullException(nameof(column))
- null
- value
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/a3ab05663c4026ad.
Report an issue: GitHub.