{"record":{"id":"42e4a010e183315d","repo":"dotnet/machinelearning","slug":"type","errorCode":null,"errorMessage":"type","messagePattern":"type","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.DataView/DataViewSchema.cs","lineNumber":300,"sourceCode":"                            _items.Add((column.Name, column.Type, annotations.GetGetterInternal(column.Index), column.Annotations));\n                    }\n                }\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)","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.DataView/DataViewSchema.cs#L282-L318","documentation":"Null-argument guard on the type parameter of DataViewSchema.Builder.Add (the strongly-typed annotation overload used by AddPrimitiveValue, GetSummaryIRowOrNull and MakeStatisticsMetadata). An annotation column cannot exist without a DataViewType, so passing null for type throws an ArgumentNullException naming 'type'; name and getter have their own separate checks.","triggerScenarios":"Passing null because the type was obtained from a lookup that failed (e.g. GetColumnOrNull returned null and .Type was dereferenced from a null); constructing types conditionally and leaving a null path.","commonSituations":"Custom transform output schema built from input columns that may be absent; annotation types fetched from a missing source column.","solutions":["Resolve the type from an existing column: var type = schema[name].Type and verify the column exists first","Use a concrete type such as NumberDataViewType.Single or a keyed/vector type factory instead of null","Fail fast with a clear message if the source type cannot be determined"],"exampleFix":"// before\nbuilder.Add(\"Score\", null, getter);\n// after\nvar type = input.Schema[\"Score\"].Type;\nbuilder.Add(\"Score\", type, getter);","handlingStrategy":"validation","validationCode":"if (type == null)\n    type = source.Schema[\"Score\"]?.Type ?? NumberDataViewType.Single;\nbuilder.Add(name, type, getter);","typeGuard":null,"tryCatchPattern":"try { builder.Add(name, type, getter); }\ncatch (ArgumentNullException e) when (e.ParamName == \"type\")\n{\n    builder.Add(name, NumberDataViewType.Single, getter);\n}","preventionTips":["Resolve DataViewType from an existing schema column rather than constructing null","Null-check any type-lookup result before use","Use well-known type singletons (NumberDataViewType.*, new VectorDataViewType(...)) instead of null placeholders"],"tags":["dotnet","mlnet","argument-null","schema-builder"],"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"}