{"record":{"id":"92059406859e3652","repo":"dotnet/machinelearning","slug":"columns","errorCode":null,"errorMessage":"columns","messagePattern":"columns","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.DataView/DataViewSchema.cs","lineNumber":450,"sourceCode":"                for (int i = 0; i < _items.Count; i++)\n                    nameMap[_items[i].Name] = i;\n\n                var columns = new Column[_items.Count];\n                for (int i = 0; i < columns.Length; i++)\n                    columns[i] = new Column(_items[i].Name, i, nameMap[_items[i].Name] != i, _items[i].Type, _items[i].Annotations);\n\n                return new DataViewSchema(columns);\n            }\n        }\n\n        /// <summary>\n        /// This constructor should only be called by <see cref=\"Builder\"/>.\n        /// </summary>\n        /// <param name=\"columns\">The input columns. The constructed instance takes ownership of the array.</param>\n        private DataViewSchema(Column[] columns)\n        {\n            if (columns == null)\n                throw new ArgumentNullException(nameof(columns));\n\n            _columns = columns;\n            _nameMap = new Dictionary<string, int>();\n            for (int i = 0; i < _columns.Length; i++)\n            {\n                Debug.Assert(_columns[i].Index == i);\n                _nameMap[_columns[i].Name] = i;\n            }\n        }\n    }\n}\n","sourceCodeStart":432,"sourceCodeEnd":462,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.DataView/DataViewSchema.cs#L432-L462","documentation":"The private DataViewSchema(Column[]) constructor throws ArgumentNullException(\"columns\") when the columns array is null. The constructor takes ownership of the array and immediately builds the name-to-index dictionary from it, so a null array is rejected. It is documented as callable only from Builder, but reflection or malformed builder state can still reach it.","triggerScenarios":"Invoking the private constructor via reflection with null; a Builder whose internal items collection was replaced with null before Create(); custom code copying the constructor pattern.","commonSituations":"Test harnesses or serializers that reconstruct DataViewSchema instances reflectively; subclassing attempts on Builder that bypass AddColumn/Create.","solutions":["Construct schemas through Builder.AddColumn + builder.Create(this) instead of the private constructor.","If using reflection, pass a non-empty (or at least non-null, possibly zero-length) Column[] array.","Ensure Builder state is never externally mutated; keep a local reference to the builder and populate it fully."],"exampleFix":"// before\nvar schema = (DataViewSchema)ctor.Invoke(new object[] { null });\n// after\nvar builder = new DataViewSchema.Builder();\nforeach (var (n, t) in cols) builder.AddColumn(n, t);\nvar schema = builder.Create(null);","handlingStrategy":"validation","validationCode":"if (columns == null) throw new ArgumentException(\"columns array required\");","typeGuard":"bool HasColumns(DataViewSchema.Column[] c) => c != null;","tryCatchPattern":"try { var schema = builder.Create(null); } catch (ArgumentNullException) { /* rebuild via Builder */ }","preventionTips":["Always build schemas via Builder.Create, never via reflection on the private ctor","Keep Column arrays non-null even when empty","Avoid external mutation of Builder internals"],"tags":["csharp","null-argument","reflection","ml-net"],"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"}