{"record":{"id":"1b4505902054e1e8","repo":"dotnet/machinelearning","slug":"unsupported-type-type-used-in-mapping","errorCode":null,"errorMessage":"Unsupported type {type} used in mapping.","messagePattern":"Unsupported type (.+?) used in mapping\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.Data/Transforms/ValueMapping.cs","lineNumber":202,"sourceCode":"    /// The DataViewHelper provides a set of static functions to create a DataView given a list of keys and values.\n    /// </summary>\n    internal class DataViewHelper\n    {\n        /// <summary>\n        /// Helper function to retrieve the Primitive type given a Type\n        /// </summary>\n        internal static PrimitiveDataViewType GetPrimitiveType(Type rawType, out bool isVectorType)\n        {\n            Type type = rawType;\n            isVectorType = false;\n            if (type.IsArray)\n            {\n                type = rawType.GetElementType();\n                isVectorType = true;\n            }\n\n            if (!type.TryGetDataKind(out InternalDataKind kind))\n                throw new InvalidOperationException($\"Unsupported type {type} used in mapping.\");\n\n            return ColumnTypeExtensions.PrimitiveTypeFromKind(kind);\n        }\n\n        /// <summary>\n        /// Helper function for a reverse lookup given value. This is used for generating the metadata of the value column.\n        /// </summary>\n\n        private static ValueGetter<VBuffer<ReadOnlyMemory<char>>> GetKeyValueGetter<TKey>(TKey[] keys)\n        {\n            return\n                (ref VBuffer<ReadOnlyMemory<char>> dst) =>\n                {\n                    var editor = VBufferEditor.Create(ref dst, keys.Length);\n                    for (int i = 0; i < keys.Length; i++)\n                        editor.Values[i] = keys[i].ToString().AsMemory();\n                    dst = editor.Commit();\n                };","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.Data/Transforms/ValueMapping.cs#L184-L220","documentation":"ValueMapping's GetPrimitiveType derives the column type for mapping keys/values from the .NET type of the mapping dictionary. When the type cannot be converted to an InternalDataKind (TryGetDataKind fails), it throws InvalidOperationException because that type is not supported in a value mapping.","triggerScenarios":"Building a ValueMappingEstimator with a dictionary whose key or value type is not a primitive ML.NET type (e.g. custom object, nullable type without support, enum handled improperly, multi-dimensional arrays); called via keyType/valueType helpers.","commonSituations":"Passing Dictionary<CustomClass, string> or Dictionary<string, MyClass?> to ValueMapping; using types not in ML.NET's supported primitive set (bool, char, numerics, string, DateTime, TimeSpan, etc.); arrays/element types of unsupported kind.","solutions":["Change the mapping dictionary's key/value types to ML.NET-supported primitives (int, float, string, bool, DateTime, etc.)","Convert unsupported values to strings or numeric codes before constructing the mapping","Split complex objects into multiple primitive-valued mappings (one per field)"],"exampleFix":"// before\nvar map = new Dictionary<string, MyObject>();\n// after\nvar map = new Dictionary<string, string>(); // map id -> serialized/selected primitive value","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool IsMlnetPrimitive(Type t) =>\n    t == typeof(bool) || t == typeof(char) || t == typeof(string) ||\n    t == typeof(int) || t == typeof(uint) || t == typeof(long) || t == typeof(ulong) ||\n    t == typeof(short) || t == typeof(ushort) || t == typeof(byte) || t == typeof(sbyte) ||\n    t == typeof(float) || t == typeof(double) || t == typeof(decimal) ||\n    t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(Guid);\nvar kvType = typeof(KeyValuePair<,>).MakeGenericType(map.GetType().GetGenericArguments());\nforeach (var t in map.GetType().GetGenericArguments())\n    if (!IsMlnetPrimitive(t)) throw new InvalidOperationException($\"Unsupported mapping type {t}\");","tryCatchPattern":null,"preventionTips":["Use only ML.NET primitive types as mapping dictionary key/value types","Avoid mapping to custom objects; map to one primitive per field","Check supported types in ValueMapping docs before building dictionaries"],"tags":["value-mapping","unsupported-type","type-mapping"],"backgroundTag":"type-mismatch","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"}