{"record":{"id":"7fa40927184a06e2","repo":"dotnet/machinelearning","slug":"specified-argument-was-out-of-the-range-of-valid-v-7fa409","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'index')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'index'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.DataView/DataViewSchema.cs","lineNumber":110,"sourceCode":"            /// </summary>\n            public bool IsHidden { get; }\n\n            /// <summary>\n            /// The type of the column.\n            /// </summary>\n            public DataViewType Type { get; }\n\n            /// <summary>\n            /// The annotations of the column.\n            /// </summary>\n            public Annotations Annotations { get; }\n\n            internal Column(string name, int index, bool isHidden, DataViewType type, Annotations annotations)\n            {\n                if (string.IsNullOrEmpty(name))\n                    throw new ArgumentNullException(nameof(name));\n                if (index < 0)\n                    throw new ArgumentOutOfRangeException(nameof(index));\n\n                Name = name;\n                Index = index;\n                IsHidden = isHidden;\n                Type = type ?? throw new ArgumentNullException(nameof(type));\n                Annotations = annotations ?? Annotations.Empty;\n            }\n\n            public override string ToString()\n            {\n                var annotationsString = (Annotations == null || Annotations.Schema.Count == 0) ?\n                    null : $\" {{{string.Join(\", \", Annotations.Schema.Select(x => x.Name))}}}\";\n                return $\"{Name}: {Type}{annotationsString}\";\n            }\n        }\n\n        /// <summary>\n        /// This class represents the schema of one column of a data view, without an attachment to a particular <see cref=\"DataViewSchema\"/>.","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.DataView/DataViewSchema.cs#L92-L128","documentation":"The DataViewSchema.Column constructor requires a non-negative index; passing a negative index throws ArgumentOutOfRangeException naming 'index'. Column.Index must be a valid position within its schema.","triggerScenarios":"Constructing a Column with index < 0 — e.g. an index from a failed name lookup (some code returns -1 for 'not found') passed straight into the constructor, or a counter bug.","commonSituations":"Translating a -1 sentinel from a lookup miss directly into column construction; loops with wrong initialization; copying indices from a legacy structure that used -1 as 'unknown'.","solutions":["Verify the index is >= 0 before constructing; treat negative values as 'not found' and handle them instead.","Check whether an earlier lookup API returned -1 for a missing name and add a branch for that case.","Correct off-by-one/initialization bugs in loops that generate indices.","Where available, build columns through Builder.Add, which assigns the index automatically."],"exampleFix":"// before\nvar column = new Column(name, lookupIndex, false, type, null); // lookupIndex may be -1\n// after\nif (lookupIndex < 0) throw new KeyNotFoundException($\"Column '{name}' not found\");\nvar column = new Column(name, lookupIndex, false, type, null);","handlingStrategy":"validation","validationCode":"if (index < 0) throw new KeyNotFoundException(\"Column lookup failed; index must be >= 0\");","typeGuard":"bool IsValidColumnIndex(int index) => index >= 0;","tryCatchPattern":null,"preventionTips":["Handle -1 sentinel from lookups before constructing columns","Prefer Builder.Add which assigns indices automatically"],"tags":["dotnet","argument-out-of-range","schema","constructor"],"backgroundTag":"value-out-of-range","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"}