{"record":{"id":"8861ce57e21fb7b9","repo":"dotnet/machinelearning","slug":"invalid-call-to-getvalue","errorCode":null,"errorMessage":"Invalid call to 'GetValue'","messagePattern":"Invalid call to 'GetValue'","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.DataView/DataViewSchema.cs","lineNumber":241,"sourceCode":"                if (column.Index >= _getters.Length)\n                    throw new ArgumentException(nameof(column));\n                var typedGetter = _getters[column.Index] as ValueGetter<TValue>;\n                if (typedGetter == null)\n                {\n                    Debug.Assert(_getters[column.Index] != null);\n                    throw new InvalidOperationException($\"Invalid call to '{nameof(GetGetter)}'\");\n                }\n                return typedGetter;\n            }\n\n            /// <summary>\n            /// Get the value of an annotation, by annotation kind (aka column name).\n            /// </summary>\n            public void GetValue<TValue>(string kind, ref TValue value)\n            {\n                var column = Schema.GetColumnOrNull(kind);\n                if (column == null)\n                    throw new InvalidOperationException($\"Invalid call to '{nameof(GetValue)}'\");\n                GetGetter<TValue>(column.Value)(ref value);\n            }\n\n            public override string ToString() => string.Join(\", \", Schema.Select(x => x.Name));\n\n            internal Delegate GetGetterInternal(int index)\n            {\n                Debug.Assert(0 <= index && index < Schema.Count);\n                return _getters[index];\n            }\n\n            /// <summary>\n            /// Class containing operations to build an <see cref=\"Annotations\"/>.\n            /// </summary>\n            public sealed class Builder\n            {\n                private readonly List<(string Name, DataViewType Type, Delegate Getter, Annotations Annotations)> _items;\n","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.DataView/DataViewSchema.cs#L223-L259","documentation":"Annotations.GetValue<TValue>(kind,...) looks up the annotation column by its kind string on the parent schema; if no column with that name exists, it throws InvalidOperationException instead of returning null. It signals that you requested an annotation kind this column's annotations simply do not carry.","triggerScenarios":"Requesting AnnotationUtils.Kinds.SlotNames on a scalar (non-vector) column; requesting KeyValues on a column that is not a key type; reading a custom annotation kind that the producing transform never added; querying annotations through the Builder copy path (GetAnnotationInfo) on a schema missing that kind.","commonSituations":"Assuming every vector column has slot names; copying annotations in a custom transform without checking the source actually contains the kind; renaming columns so the annotation lookup by kind fails.","solutions":["Call Schema.GetColumnOrNull(kind) (or the TryGet pattern) yourself and skip the annotation when absent","Guard with column.Type judgment: only ask for SlotNames on vector types and KeyValues on key types","If writing a transform, copy annotations selectively with Annotations.Add(source, selector) instead of assuming kinds exist"],"exampleFix":"// before\nannotations.GetValue<VBuffer<ReadOnlyMemory<char>>>(AnnotationUtils.Kinds.SlotNames, ref slotNames);\n// after\nif (Schema.GetColumnOrNull(AnnotationUtils.Kinds.SlotNames) != null)\n    annotations.GetValue<VBuffer<ReadOnlyMemory<char>>>(AnnotationUtils.Kinds.SlotNames, ref slotNames);","handlingStrategy":"validation","validationCode":"bool hasKind = Schema.GetColumnOrNull(kind) != null;\nif (!hasKind) return; // or substitute a default value","typeGuard":"bool HasAnnotation(DataViewSchema schema, string kind) =>\n    schema.GetColumnOrNull(kind) != null;","tryCatchPattern":"try { annotations.GetValue<TValue>(kind, ref value); }\ncatch (InvalidOperationException)\n{\n    value = default; // annotation kind not present on this column\n}","preventionTips":["Only request SlotNames on vector-typed columns and KeyValues on key-typed columns","Check GetColumnOrNull(kind) before GetValue","Use AnnotationUtils.Kinds constants to avoid typos in kind names","When writing transforms, copy annotations with a selector rather than assuming kinds exist"],"tags":["dotnet","mlnet","annotations","missing-annotation"],"backgroundTag":"resource-not-found","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}