{"record":{"id":"5d2342d761655bd2","repo":"stride3d/stride","slug":"cannot-create-literalvalue-from-the-provided-words","errorCode":null,"errorMessage":"Cannot create LiteralValue from the provided words","messagePattern":"Cannot create LiteralValue from the provided words","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Spirv/Literals/LiteralValue.cs","lineNumber":102,"sourceCode":"            Span<char> sb = stackalloc char[words.Length * 4];\n            for (int i = 0; i < words.Length; i++)\n            {\n                for (int j = 0; j < 4; j++)\n                {\n                    var c = (char)((words[i] >> (8 * j)) & 0xFF);\n                    if (c == 0)\n                        break;\n                    sb[i * 4 + j] = c;\n                }\n            }\n            Unsafe.As<T, string>(ref value) = SPool.GetOrAdd(sb.Contains('\\0') ? sb[0..sb.IndexOf('\\0')] : sb);\n        }\n        else if (value is Enum)\n            Unsafe.As<T, int>(ref value) = words[0];\n        else if (typeof(T).Name.Contains(\"LiteralArray\"))\n            throw new NotImplementedException(\"Use LiteralArray<T>.From instead\");\n        else\n            throw new NotImplementedException(\"Cannot create LiteralValue from the provided words\");\n\n        Value = value;\n\n        MemoryOwner = MemoryOwner<int>.Allocate(words.Length, AllocationMode.Clear);\n        words.CopyTo(MemoryOwner.Span);\n        UpdateMemory();\n    }\n    public LiteralValue(T value, bool dispose = false)\n    {\n        this.dispose = dispose;\n        Value = value;\n        MemoryOwner = MemoryOwner<int>.Empty;\n        UpdateMemory();\n    }\n\n    void UpdateMemory()\n    {\n        int wordCount = Value switch","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Spirv/Literals/LiteralValue.cs#L84-L120","documentation":"Fallback branch of the LiteralValue words-based constructor: if T is not a primitive, not an Enum, and not a LiteralArray-named type, the constructor cannot know how to decode the raw int words into a T and throws NotImplementedException. Only types with an explicit encoding rule are accepted.","triggerScenarios":"new LiteralValue<T>(words) where T is e.g. char, decimal, IntPtr, a custom struct, or an unsupported generic type — anything outside {bool, byte, sbyte, short, ushort, Half, int, uint, float, long, ulong, double, (int,int), string, Enum}.","commonSituations":"Deserializing SPIR-V OpConstant/OpLiteral operands with the wrong assumed type; generic parsing code parameterized over T; changing a constant's declared type in shader tooling without converting its words.","solutions":["Decode the words into a supported type first (e.g. BitConverter/Unsafe reinterpret) and construct LiteralValue with that type.","If T is an enum, ensure it actually derives from Enum (an interface won't match the `value is Enum` branch).","For arrays use LiteralArray<T>.From; for strings ensure the words are null-terminated/word-padded UTF-8.","Add a branch in the constructor if a new T encoding is genuinely required."],"exampleFix":"// before\nvar lit = new LiteralValue<char>(words);\n// after\nvar lit = new LiteralValue<ushort>(words); // then cast to char","handlingStrategy":"validation","validationCode":"static readonly HashSet<Type> Allowed = new()\n  { typeof(bool), typeof(byte), typeof(sbyte), typeof(short), typeof(ushort),\n    typeof(Half), typeof(int), typeof(uint), typeof(float), typeof(long),\n    typeof(ulong), typeof(double), typeof((int,int)), typeof(string) };\nbool ok = Allowed.Contains(typeof(T)) || typeof(Enum).IsAssignableFrom(typeof(T));","typeGuard":"static bool IsDecodableLiteral<T>() => Allowed.Contains(typeof(T)) || typeof(Enum).IsAssignableFrom(typeof(T));","tryCatchPattern":"try { lit = new LiteralValue<T>(words); }\ncatch (NotImplementedException ex) when (ex.Message.Contains(\"Cannot create LiteralValue\")) { /* decode words manually into a supported type */ }","preventionTips":["Only feed primitive, enum, string, or (int,int) T values into the words constructor.","Use Unsafe/BitConverter to reinterpret exotic types into int/float words first.","Keep a table mapping SPIR-V operand kinds to the .NET types LiteralValue supports."],"tags":["spirv","literals","unsupported-type","decoding"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}