dotnet/machinelearning · error · ArgumentNullException
Value cannot be null. (Parameter 'getter') Delegate at index
Error message
Value cannot be null. (Parameter 'getter')
Delegate at index '{i}' of getters was null. What it means
The Annotations constructor validates every delegate in the getters array: if any element is null it throws ArgumentNullException naming 'getter' with a message identifying the offending index i. Annotations are backed by one typed getter per annotation slot, so a null getter would break all subsequent value access.
Source
Thrown at src/Microsoft.ML.DataView/DataViewSchema.cs:204
/// <summary>
/// Create an annotations row by supplying the schema columns and the getter delegates for all the values.
/// </summary>
/// <remarks>
/// Note: The <paramref name="getters"/> array is owned by this <see cref="Annotations"/> instance.
/// </remarks>
internal Annotations(DataViewSchema schema, Delegate[] getters)
{
Debug.Assert(schema != null);
Debug.Assert(getters != null);
Debug.Assert(schema.Count == getters.Length);
// Check all getters.
for (int i = 0; i < schema.Count; i++)
{
var getter = getters[i];
if (getter == null)
throw new ArgumentNullException(nameof(getter), $"Delegate at index '{i}' of {nameof(getters)} was null.");
Utils.MarshalActionInvoke(CheckGetter<int>, schema[i].Type.RawType, getter);
}
Schema = schema;
_getters = getters;
}
private void CheckGetter<TValue>(Delegate getter)
{
var typedGetter = getter as ValueGetter<TValue>;
if (typedGetter == null)
throw new ArgumentNullException(nameof(getter), $"Getter of type '{typeof(TValue)}' expected, but {getter.GetType()} found");
}
/// <summary>
/// Get a getter delegate for one value of the annotations row.
/// </summary>
public ValueGetter<TValue> GetGetter<TValue>(DataViewSchema.Column column)
{View on GitHub (pinned to 7b76e69cf9)
Solutions
- Ensure every element of the getters array is a non-null typed delegate (ValueGetter<TValue>) before calling the constructor.
- Add your own null check with a clearer message at the point you build the array.
- Fix the conditional/loop logic that leaves an entry unassigned.
- Only pass arrays whose length equals schema.Count (asserted by the constructor) and fully populated.
Example fix
// before
var getters = new Delegate[] { GetNameGetter(), null, GetCountGetter() };
var annotations = new Annotations(schema, getters);
// after
var getters = new Delegate[] { GetNameGetter(), GetWeightsGetter(), GetCountGetter() };
if (getters.Any(g => g == null)) throw new InvalidOperationException("All annotation getters must be provided");
var annotations = new Annotations(schema, getters); Defensive patterns
Strategy: validation
Validate before calling
if (getters == null || getters.Length != schema.Count || getters.Any(g => g == null))
throw new InvalidOperationException("Every annotation slot needs a non-null getter"); Type guard
bool GettersComplete(Delegate[] g) => g != null && g.All(x => x != null);
Try / catch
try { var ann = new Annotations(schema, getters); } catch (ArgumentNullException ex) { /* ex.Message names the null index */ } Prevention
- Build getter arrays in one pass with no conditional skips
- Assert getters.Length == schema.Count before construction
When it happens
Trigger: Building an Annotations object with a getters array that contains a null element — e.g. constructing delegates in a loop with conditional assignment, or a factory returning null for one annotation kind.
Common situations: Custom trainers/transforms emitting annotation getters (slot names, per-slot metrics) where one getter function returned null; parallel delegate construction where an entry is skipped.
Related errors
- Value cannot be null. (Parameter 'getter') Getter of type '{
- 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/d5d12710fe49d2bc.
Report an issue: GitHub.