{"record":{"id":"4c0d36ed5f67d2db","repo":"stride3d/stride","slug":"unsupported-literal-type-value-gettype","errorCode":null,"errorMessage":"Unsupported literal type: {value.GetType()}","messagePattern":"Unsupported literal type: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Context.Constants.cs","lineNumber":286,"sourceCode":"        return new(Buffer.AddData(new OpConstantComposite(GetOrRegister(type), Bound++, new(values))));\n    }\n\n    public Literal CreateLiteral(object value, TextLocation location = default)\n    {\n        return value switch\n        {\n            bool i => new BoolLiteral(i, location),\n            sbyte i => new IntegerLiteral(new(8, false, true), i, location),\n            byte i => new IntegerLiteral(new(8, false, false), i, location),\n            short i => new IntegerLiteral(new(16, false, true), i, location),\n            ushort i => new IntegerLiteral(new(16, false, false), i, location),\n            int i => new IntegerLiteral(new(32, false, true), i, location),\n            uint i => new IntegerLiteral(new(32, false, false), i, location),\n            long i => new IntegerLiteral(new(64, false, true), i, location),\n            ulong i => new IntegerLiteral(new(64, false, false), (long)i, location),\n            float i => new FloatLiteral(new(32, true, true), i, location),\n            double i => new FloatLiteral(new(64, true, true), i, location),\n            _ => throw new NotSupportedException($\"Unsupported literal type: {value.GetType()}\"),\n        };\n    }\n\n    public SpirvValue CompileConstant(object value, TextLocation location = default)\n    {\n        return CompileConstantLiteral(CreateLiteral(value, location));\n    }\n\n    public SpirvValue CompileConstantLiteral(Literal literal)\n    {\n        object literalValue = literal switch\n        {\n            BoolLiteral lit => lit.Value,\n            IntegerLiteral lit => lit.Suffix switch\n            {\n                { Size: > 32, Signed: false } => lit.ULongValue,\n                { Size: > 32, Signed: true } => lit.LongValue,\n                { Signed: false } => lit.UIntValue,","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Context.Constants.cs#L268-L304","documentation":"CreateLiteral converts a boxed .NET object into a strongly-typed Literal for SPIR-V emission. Only bool and the sbyte..double numeric types are mapped; any other runtime type (string, decimal, IntPtr, custom struct, enum, etc.) throws NotSupportedException naming the value's actual type.","triggerScenarios":"Calling CompileConstant(value) or CreateLiteral(value) with an object whose runtime type is not in {bool, sbyte, byte, short, ushort, int, uint, long, ulong, float, double} — e.g. a decimal, a string, an enum value, or a nullable that boxed as something else.","commonSituations":"Passing shader constant values loaded from config/JSON where numbers deserialized as decimal or double-string; passing enum constants instead of their underlying integer; using checked arithmetic producing decimal intermediates.","solutions":["Convert the value to a supported primitive before calling (e.g. (int)myEnum, Convert.ToDouble(value), (double)(decimal)x)","If the constant comes from deserialization, configure the deserializer to produce int/float/double instead of decimal/string","Extend CreateLiteral's switch to map the needed type (e.g. decimal => new FloatLiteral(new(64,...), (double)i, location))"],"exampleFix":"// before\nCompileConstant(someDecimalValue); // throws\n// after\nCompileConstant((double)someDecimalValue);\n// or for enums\nCompileConstant((int)MyEnum.Value);","handlingStrategy":"type-guard","validationCode":"static readonly HashSet<Type> SupportedLiteralTypes = new() {\n    typeof(bool), typeof(sbyte), typeof(byte), typeof(short), typeof(ushort),\n    typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double) };\nbool IsSupportedLiteral(object v) => v != null && SupportedLiteralTypes.Contains(v.GetType());","typeGuard":"static bool IsNumericLiteral(object v) => v is bool or sbyte or byte or short or ushort or int or uint or long or ulong or float or double;","tryCatchPattern":"try\n{\n    var spirvValue = context.CompileConstant(rawValue);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Unsupported literal type\"))\n{\n    // convert to a supported primitive and retry\n    var spirvValue = context.CompileConstant(Convert.ToDouble(rawValue));\n}","preventionTips":["Always pass unboxed CLR primitives, not decimal/string/enum/nullable wrappers","Normalize deserialized config values (decimal -> double) before compiling constants","Convert enums to their underlying int with an explicit cast","Guard call sites with a pattern check (v is int or float or double ...) before invoking"],"tags":["literal","type-mismatch","not-supported","shader-compilation"],"backgroundTag":"type-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}