{"record":{"id":"d5d12710fe49d2bc","repo":"dotnet/machinelearning","slug":"value-cannot-be-null-parameter-getter-delegat","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'getter')\nDelegate at index '{i}' of getters was null.","messagePattern":"Value cannot be null\\. \\(Parameter 'getter'\\)\nDelegate at index '(.+?)' of getters was null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.DataView/DataViewSchema.cs","lineNumber":204,"sourceCode":"\n            /// <summary>\n            /// Create an annotations row by supplying the schema columns and the getter delegates for all the values.\n            /// </summary>\n            /// <remarks>\n            /// Note: The <paramref name=\"getters\"/> array is owned by this <see cref=\"Annotations\"/> instance.\n            /// </remarks>\n            internal Annotations(DataViewSchema schema, Delegate[] getters)\n            {\n                Debug.Assert(schema != null);\n                Debug.Assert(getters != null);\n\n                Debug.Assert(schema.Count == getters.Length);\n                // Check all getters.\n                for (int i = 0; i < schema.Count; i++)\n                {\n                    var getter = getters[i];\n                    if (getter == null)\n                        throw new ArgumentNullException(nameof(getter), $\"Delegate at index '{i}' of {nameof(getters)} was null.\");\n                    Utils.MarshalActionInvoke(CheckGetter<int>, schema[i].Type.RawType, getter);\n                }\n                Schema = schema;\n                _getters = getters;\n            }\n\n            private void CheckGetter<TValue>(Delegate getter)\n            {\n                var typedGetter = getter as ValueGetter<TValue>;\n                if (typedGetter == null)\n                    throw new ArgumentNullException(nameof(getter), $\"Getter of type '{typeof(TValue)}' expected, but {getter.GetType()} found\");\n            }\n\n            /// <summary>\n            /// Get a getter delegate for one value of the annotations row.\n            /// </summary>\n            public ValueGetter<TValue> GetGetter<TValue>(DataViewSchema.Column column)\n            {","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.DataView/DataViewSchema.cs#L186-L222","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar getters = new Delegate[] { GetNameGetter(), null, GetCountGetter() };\nvar annotations = new Annotations(schema, getters);\n// after\nvar getters = new Delegate[] { GetNameGetter(), GetWeightsGetter(), GetCountGetter() };\nif (getters.Any(g => g == null)) throw new InvalidOperationException(\"All annotation getters must be provided\");\nvar annotations = new Annotations(schema, getters);","handlingStrategy":"validation","validationCode":"if (getters == null || getters.Length != schema.Count || getters.Any(g => g == null))\n    throw new InvalidOperationException(\"Every annotation slot needs a non-null getter\");","typeGuard":"bool GettersComplete(Delegate[] g) => g != null && g.All(x => x != null);","tryCatchPattern":"try { var ann = new Annotations(schema, getters); } catch (ArgumentNullException ex) { /* ex.Message names the null index */ }","preventionTips":["Build getter arrays in one pass with no conditional skips","Assert getters.Length == schema.Count before construction"],"tags":["dotnet","null-argument","delegate","annotations"],"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"}