dotnet/machinelearning · error · ArgumentNullException
nameof(values)
Error message
nameof(values)
What it means
PrimitiveColumnContainer<T>(IEnumerable<T> values) rejects a null enumerable with ArgumentNullException(nameof(values)); it then appends each value. This is a fail-fast guard — the elements themselves may be any T.
Source
Thrown at src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs:30
namespace Microsoft.Data.Analysis
{
/// <summary>
/// PrimitiveColumnContainer is just a store for the column data. APIs that want to change the data must be defined in PrimitiveDataFrameColumn
/// </summary>
/// <typeparam name="T"></typeparam>
internal partial class PrimitiveColumnContainer<T> : IEnumerable<T?>
where T : unmanaged
{
public IList<ReadOnlyDataFrameBuffer<T>> Buffers = new List<ReadOnlyDataFrameBuffer<T>>();
// To keep the mapping simple, each buffer is mapped 1v1 to a nullBitMapBuffer
// A set bit implies a valid value. An unset bit => null value
public IList<ReadOnlyDataFrameBuffer<byte>> NullBitMapBuffers = new List<ReadOnlyDataFrameBuffer<byte>>();
public PrimitiveColumnContainer(IEnumerable<T> values)
{
values = values ?? throw new ArgumentNullException(nameof(values));
foreach (T value in values)
{
Append(value);
}
}
public PrimitiveColumnContainer(IEnumerable<T?> values)
{
values = values ?? throw new ArgumentNullException(nameof(values));
foreach (T? value in values)
{
Append(value);
}
}
public PrimitiveColumnContainer(ReadOnlyMemory<byte> buffer, ReadOnlyMemory<byte> nullBitMap, int length, int nullCount)
{
ReadOnlyDataFrameBuffer<T> dataBuffer;View on GitHub (pinned to 7b76e69cf9)
Solutions
- Coalesce to empty: values ?? Enumerable.Empty<T>().
- Null-check at the call site before constructing.
- Fix the producer method to return an empty sequence rather than null.
- Initialize collections with Array.Empty<T>() instead of null.
Example fix
// before var container = new PrimitiveColumnContainer<int>(GetValues()); // may return null // after var values = GetValues() ?? Enumerable.Empty<int>(); var container = new PrimitiveColumnContainer<int>(values);
Defensive patterns
Strategy: validation
Validate before calling
if (values is null)
throw new ArgumentException("values must not be null; pass an empty sequence instead"); Type guard
bool isUsableSequence<T>(IEnumerable<T> values) => values is not null;
Try / catch
try { var c = new PrimitiveColumnContainer<int>(values); }
catch (ArgumentNullException ex) when (ex.ParamName == "values")
{ /* null enumerable: coalesce to Enumerable.Empty<int>() and retry */ } Prevention
- Coalesce possibly-null sequences with ?? Enumerable.Empty<T>().
- Return empty collections, never null, from producers.
- Enable nullable reference types to catch null flows at compile time.
- Default-initialize collections to Array.Empty<T>().
When it happens
Trigger: Passing a null IEnumerable<T> to the constructor, typically from an uninitialized variable or a method returning null instead of an empty sequence.
Common situations: Deserialized configuration holding null collections; helper methods returning null on failure; dictionary lookups yielding null lists.
Related errors
- Strings.InconsistentNullBitMapAndNullCount
- {fieldType.Name}
- MismatchedColumnLengths
- Exception of type 'System.ArgumentException' was thrown.
- kind
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/b2f90755670737bc.
Report an issue: GitHub.