{"record":{"id":"e31c8e9fa2230da5","repo":"dotnet/machinelearning","slug":"not-implemented-type-typeof-t","errorCode":null,"errorMessage":"Not implemented type {typeof(T)}","messagePattern":"Not implemented type (.+?)","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.OnnxTransformer/OnnxUtils.cs","lineNumber":537,"sourceCode":"                    { typeof(UInt32) , InternalDataKind.U4},\n                    { typeof(UInt64) , InternalDataKind.U8},\n                    { typeof(String) , InternalDataKind.TX},\n                    { typeof(Boolean) , InternalDataKind.BL},\n                    { typeof(SByte) , InternalDataKind.I1},\n                    { typeof(Byte) , InternalDataKind.U1},\n                };\n\n        /// <summary>\n        /// Creates a NamedOnnxValue from a scalar value.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of the Tensor contained in the NamedOnnxValue.</typeparam>\n        /// <param name=\"name\">The name of the NamedOnnxValue.</param>\n        /// <param name=\"data\">The data values of the Tensor.</param>\n        /// <returns>NamedOnnxValue</returns>\n        public static NamedOnnxValue CreateScalarNamedOnnxValue<T>(string name, T data)\n        {\n            if (!_onnxTypeMap.Contains(typeof(T)))\n                throw new NotImplementedException($\"Not implemented type {typeof(T)}\");\n\n            if (typeof(T) == typeof(ReadOnlyMemory<char>))\n                return NamedOnnxValue.CreateFromTensor<string>(name, new DenseTensor<string>(new string[] { data.ToString() }, new int[] { 1, 1 }));\n\n            return NamedOnnxValue.CreateFromTensor<T>(name, new DenseTensor<T>(new T[] { data }, new int[] { 1, 1 }));\n        }\n\n        /// <summary>\n        /// Create a NamedOnnxValue from vbuffer span. Checks if the tensor type\n        /// is supported by OnnxRuntime prior to execution.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of the Tensor contained in the NamedOnnxValue.</typeparam>\n        /// <param name=\"name\">The name of the NamedOnnxValue.</param>\n        /// <param name=\"data\">A span containing the data</param>\n        /// <param name=\"shape\">The shape of the Tensor being created.</param>\n        /// <returns>NamedOnnxValue</returns>\n        public static NamedOnnxValue CreateNamedOnnxValue<T>(string name, ReadOnlySpan<T> data, OnnxShape shape)\n        {","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.OnnxTransformer/OnnxUtils.cs#L519-L555","documentation":"CreateScalarNamedOnnxValue wraps a single scalar value into a NamedOnnxValue/DenseTensor for ONNX Runtime. It only supports the types registered in _onnxTypeMap (float, double, int, long, string/ReadOnlyMemory<char>, etc.); any other T throws NotImplementedException.","triggerScenarios":"Calling OnnxUtils.CreateScalarNamedOnnxValue<T> with a T not in the type map — e.g. byte, short, bool, decimal, DateTime, or a user type — usually via custom code feeding values into ONNX scoring.","commonSituations":"Passing a C# bool or Int16 column into an ONNX model expecting int32; custom transform/feeder code using unsupported CLR types; type changed after a refactor so T no longer matches the model's expected input type.","solutions":["Convert the value to a supported type before calling (e.g. Convert.ToSingle / ToInt64) matching the model input's ONNX type.","Check OnnxUtils._onnxTypeMap for the supported set and cast to one of those types.","If strings are needed, pass ReadOnlyMemory<char> (or string) which has a special branch.","Add a mapping/registration for the type in _onnxTypeMap if you control the library fork."],"exampleFix":"// before\nvar v = OnnxUtils.CreateScalarNamedOnnxValue(name, myBool);\n// after\nvar v = OnnxUtils.CreateScalarNamedOnnxValue(name, myBool ? 1L : 0L);","handlingStrategy":"type-guard","validationCode":"// C#: check T is supported before calling\nstatic bool IsOnnxSupported<T>() =>\n    typeof(T) == typeof(float) || typeof(T) == typeof(double) ||\n    typeof(T) == typeof(int) || typeof(T) == typeof(long) ||\n    typeof(T) == typeof(ReadOnlyMemory<char>);","typeGuard":"static bool IsSupportedOnnxScalar<T>(T v) => IsOnnxSupported<T>();","tryCatchPattern":"try { var v = OnnxUtils.CreateScalarNamedOnnxValue(name, data); }\ncatch (NotImplementedException) { /* convert to float/long/string and retry */ }","preventionTips":["Match C# types to the ONNX model's declared input types (float32/int64/string).","Convert bool/short/byte values to int/long/float before feeding ONNX.","Centralize ONNX value creation behind one typed helper that validates types."],"tags":["onnx","not-implemented","type-mismatch","csharp"],"backgroundTag":"unsupported-dtype","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"}