{"record":{"id":"b2f90755670737bc","repo":"dotnet/machinelearning","slug":"nameof-values","errorCode":null,"errorMessage":"nameof(values)","messagePattern":"nameof\\(values\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs","lineNumber":30,"sourceCode":"\nnamespace Microsoft.Data.Analysis\n{\n    /// <summary>\n    /// PrimitiveColumnContainer is just a store for the column data. APIs that want to change the data must be defined in PrimitiveDataFrameColumn\n    /// </summary>\n    /// <typeparam name=\"T\"></typeparam>\n    internal partial class PrimitiveColumnContainer<T> : IEnumerable<T?>\n        where T : unmanaged\n    {\n        public IList<ReadOnlyDataFrameBuffer<T>> Buffers = new List<ReadOnlyDataFrameBuffer<T>>();\n\n        // To keep the mapping simple, each buffer is mapped 1v1 to a nullBitMapBuffer\n        // A set bit implies a valid value. An unset bit => null value\n        public IList<ReadOnlyDataFrameBuffer<byte>> NullBitMapBuffers = new List<ReadOnlyDataFrameBuffer<byte>>();\n\n        public PrimitiveColumnContainer(IEnumerable<T> values)\n        {\n            values = values ?? throw new ArgumentNullException(nameof(values));\n            foreach (T value in values)\n            {\n                Append(value);\n            }\n        }\n\n        public PrimitiveColumnContainer(IEnumerable<T?> values)\n        {\n            values = values ?? throw new ArgumentNullException(nameof(values));\n            foreach (T? value in values)\n            {\n                Append(value);\n            }\n        }\n\n        public PrimitiveColumnContainer(ReadOnlyMemory<byte> buffer, ReadOnlyMemory<byte> nullBitMap, int length, int nullCount)\n        {\n            ReadOnlyDataFrameBuffer<T> dataBuffer;","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs#L12-L48","documentation":"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.","triggerScenarios":"Passing a null IEnumerable<T> to the constructor, typically from an uninitialized variable or a method returning null instead of an empty sequence.","commonSituations":"Deserialized configuration holding null collections; helper methods returning null on failure; dictionary lookups yielding null lists.","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."],"exampleFix":"// before\nvar container = new PrimitiveColumnContainer<int>(GetValues()); // may return null\n// after\nvar values = GetValues() ?? Enumerable.Empty<int>();\nvar container = new PrimitiveColumnContainer<int>(values);","handlingStrategy":"validation","validationCode":"if (values is null)\n    throw new ArgumentException(\"values must not be null; pass an empty sequence instead\");","typeGuard":"bool isUsableSequence<T>(IEnumerable<T> values) => values is not null;","tryCatchPattern":"try { var c = new PrimitiveColumnContainer<int>(values); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"values\")\n{ /* null enumerable: coalesce to Enumerable.Empty<int>() and retry */ }","preventionTips":["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>()."],"tags":["argument-null-exception","constructor","dataframe","null-check"],"backgroundTag":"null-argument","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}