{"record":{"id":"40f245b21df2fbf7","repo":"dotnet/machinelearning","slug":"getter","errorCode":null,"errorMessage":"getter","messagePattern":"getter","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.DataView/DataViewSchema.cs","lineNumber":302,"sourceCode":"                }\n\n                /// <summary>\n                /// Add one annotation column, strongly-typed version.\n                /// </summary>\n                /// <typeparam name=\"TValue\">The type of the value.</typeparam>\n                /// <param name=\"name\">The annotation name.</param>\n                /// <param name=\"type\">The annotation type.</param>\n                /// <param name=\"getter\">The getter delegate.</param>\n                /// <param name=\"annotations\">Annotations of the input column. Note that annotations on an annotation column is somewhat rare\n                /// except for certain types (for example, slot names for a vector, key values for something of key type).</param>\n                public void Add<TValue>(string name, DataViewType type, ValueGetter<TValue> getter, Annotations annotations = null)\n                {\n                    if (string.IsNullOrEmpty(name))\n                        throw new ArgumentNullException(nameof(name));\n                    if (type == null)\n                        throw new ArgumentNullException(nameof(type));\n                    if (getter == null)\n                        throw new ArgumentNullException(nameof(getter));\n                    if (type.RawType != typeof(TValue))\n                        throw new ArgumentException($\"{nameof(type)}.{nameof(type.RawType)} must be of type '{typeof(TValue).FullName}'.\", nameof(type));\n\n                    _items.Add((name, type, getter, annotations));\n                }\n\n                /// <summary>\n                /// Add one annotation column, weakly-typed version.\n                /// </summary>\n                /// <param name=\"name\">The annotation name.</param>\n                /// <param name=\"type\">The annotation type.</param>\n                /// <param name=\"getter\">The getter delegate that provides the value. Note that the type of the getter is still checked\n                /// inside this method.</param>\n                /// <param name=\"annotations\">Annotations of the input column. Note that annotations on an annotation column is somewhat rare\n                /// except for certain types (for example, slot names for a vector, key values for something of key type).</param>\n                public void Add(string name, DataViewType type, Delegate getter, Annotations annotations = null)\n                {\n                    if (string.IsNullOrEmpty(name))","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.DataView/DataViewSchema.cs#L284-L320","documentation":"Builder.Add<TValue> requires a non-null ValueGetter<TValue>; the delegate is what cursors will call to read the value, so a null getter would crash later at row-iteration time. The builder throws ArgumentNullException 'getter' eagerly instead.","triggerScenarios":"Passing null for a placeholder column you intended to fill later; passing a method group whose signature doesn't match ValueGetter<TValue> so the compiler resolved null via a conditional expression; wiring a getter from a disposed/absent source row.","commonSituations":"Custom transforms that copy some columns but stub others with null; generated schema code where getter assignment is conditional.","solutions":["Always supply a real delegate, e.g. (ref float v) => v = 0 for stubs","Bind the getter to the source row's GetGetter: value => src.GetGetter<TValue>(col)(ref value) pattern","If the column should not exist, do not Add it at all rather than adding a null getter"],"exampleFix":"// before\nbuilder.Add(\"Score\", type, null);\n// after\nvar srcGetter = input.Row.GetGetter<float>(input.Schema[\"Score\"]);\nbuilder.Add(\"Score\", type, (ref float v) => srcGetter(ref v));","handlingStrategy":"validation","validationCode":"if (getter == null)\n    getter = (ValueGetter<TValue>)((ref TValue v) => v = default);\nbuilder.Add(name, type, getter);","typeGuard":null,"tryCatchPattern":"try { builder.Add(name, type, getter); }\ncatch (ArgumentNullException e) when (e.ParamName == \"getter\")\n{\n    builder.Add(name, type, (ref TValue v) => v = default);\n}","preventionTips":["Bind getters to the source row's GetGetter instead of leaving null","Omit columns you cannot supply rather than adding null getters","Avoid 'as ValueGetter<TValue>' casts that silently yield null"],"tags":["dotnet","mlnet","argument-null","delegate"],"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"}