{"record":{"id":"8ed35d9f3a0fd168","repo":"DapperLib/Dapper","slug":"the-type-value-gettype-name-is-not-supported","errorCode":null,"errorMessage":"The type '{value.GetType().Name}' is not supported for SQL literals.","messagePattern":"The type '(.+?)' is not supported for SQL literals\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"Dapper/SqlMapper.cs","lineNumber":2504,"sourceCode":"                                    sb = GetStringBuilder().Append('(');\r\n                                    first = false;\r\n                                }\r\n                                else\r\n                                {\r\n                                    sb!.Append(',');\r\n                                }\r\n                                sb.Append(Format(subval));\r\n                            }\r\n                            if (first)\r\n                            {\r\n                                return \"(select null where 1=0)\";\r\n                            }\r\n                            else\r\n                            {\r\n                                return sb!.Append(')').ToStringRecycle();\r\n                            }\r\n                        }\r\n                        throw new NotSupportedException($\"The type '{value.GetType().Name}' is not supported for SQL literals.\");\r\n                }\r\n            }\r\n        }\r\n\r\n        internal static void ReplaceLiterals(IParameterLookup parameters, IDbCommand command, IList<LiteralToken> tokens)\r\n        {\r\n            var sql = command.CommandText;\r\n            foreach (var token in tokens)\r\n            {\r\n                object? value = parameters[token.Member];\r\n#pragma warning disable 0618\r\n                string text = Format(value);\r\n#pragma warning restore 0618\r\n                sql = sql.Replace(token.Token, text);\r\n            }\r\n            command.CommandText = sql;\r\n        }\r\n\r","sourceCodeStart":2486,"sourceCodeEnd":2522,"githubUrl":"https://github.com/DapperLib/Dapper/blob/72a54c475f75e18cb93cba0809d00a5e6e49efd9/Dapper/SqlMapper.cs#L2486-L2522","documentation":"Thrown by `SqlMapper.Format(object?)` when a value used in a literal substitution (`{=name}`) is of a type Dapper will not inline as a SQL literal. Format only inlines numeric primitives (bool, byte/sbyte, ushort/short, uint/int, ulong/long, float, double, decimal) and recursively-formatted enumerables of those; everything else — strings, DateTime, Guid, TimeSpan, char, enums of non-int backing, custom types — falls through to NotSupportedException. This is intentional: inlining strings/dates would risk SQL injection.","triggerScenarios":"Using the literal syntax `where created = {=Created}` where `Created` is a DateTime, or `where name = {=Name}` where Name is a string; passing a Guid, TimeSpan, or a custom struct to a `{=...}` token. The token is resolved by ReplaceLiterals (SqlMapper.cs:2509) which calls Format on the member value.","commonSituations":"Confusing literal substitution `{=x}` (safe only for numbers) with normal parameterization `@x`; trying to inline a date or GUID for a provider that needs it inlined; using `{=}` on a string for convenience.","solutions":["Use a normal parameter (`@name`) instead of `{=name}` for strings, dates, Guids, and other non-numeric values.","If you must inline a date/guid, pre-format it to a SQL-safe string literal yourself and only then use it (with extreme care), or keep it parameterized.","Register a custom literal type handler / convert the value to a supported primitive before substitution.","Double-check that the literal token points at a numeric column/value."],"exampleFix":"// before (DateTime not supported as literal)\nvar sql = \"select * from t where created = {=AsOf}\";\nvar rows = cnn.Query<T>(sql, new { AsOf = DateTime.UtcNow });\n// after\nvar sql = \"select * from t where created = @AsOf\";\nvar rows = cnn.Query<T>(sql, new { AsOf = DateTime.UtcNow });","handlingStrategy":"validation","validationCode":"// Only inline numeric literals with {=}; parameterize everything else.\nvar sql = isNumeric ? $\"... {=Value}\" : \"... @Value\";","typeGuard":"static bool IsLiteralSafe(object? v) => v is bool or byte or sbyte or short or ushort or int or uint or long or ulong or float or double or decimal;","tryCatchPattern":null,"preventionTips":["Reserve {=} for numeric values; use @params for strings/dates/guids.","Never inline strings/dates via literals — SQL injection risk.","Pre-format unsupported types yourself only if strictly necessary."],"tags":["dapper","literals","type-conversion","security"],"backgroundTag":null,"analyzedSha":"72a54c475f75e18cb93cba0809d00a5e6e49efd9","analyzedAt":"2026-08-13T14:18:18.115Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}