{"record":{"id":"4edfbf45a5d1292a","repo":"stride3d/stride","slug":"can-t-convert-operand-to-type-typeof-t","errorCode":null,"errorMessage":"Can't convert operand to type {typeof(T)}","messagePattern":"Can't convert operand to type (.+?)","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Spirv/SpvLiteral.cs","lineNumber":168,"sourceCode":"                var result = LiteralArray<float>.From(Words);\n                return Unsafe.As<LiteralArray<float>, T>(ref result);\n            }\n            else if (tmp is LiteralArray<double>)\n            {\n                var result = LiteralArray<double>.From(Words);\n                return Unsafe.As<LiteralArray<double>, T>(ref result);\n            }\n            else if (tmp is LiteralArray<bool>)\n            {\n                var result = LiteralArray<bool>.From(Words);\n                return Unsafe.As<LiteralArray<bool>, T>(ref result);\n            }\n            else if (tmp is LiteralArray<(int, int)>)\n            {\n                var result = LiteralArray<(int, int)>.From(Words);\n                return Unsafe.As<LiteralArray<(int, int)>, T>(ref result);\n            }\n            else throw new NotImplementedException(\"Can't convert operand to type \" + typeof(T));\n        }\n        else throw new NotImplementedException($\"Can't convert operand to type {typeof(T)}\");\n        return tmp;\n    }\n\n    public override string ToString()\n    {\n        return Kind switch\n        {\n            OperandKind.LiteralString => To<LiteralString>().Value,\n            OperandKind.IdRef => $\"%{Words[0] + Offset}\",\n            OperandKind.IdResultType => $\"%{Words[0] + Offset}\",\n            OperandKind.PairLiteralIntegerIdRef => $\"{Words[0]} %{Words[0] + Offset}\",\n            OperandKind.MemoryAccess => $\"{ToEnum<Specification.MemoryAccessMask>()}\",\n            OperandKind.MemoryModel => $\"{ToEnum<Specification.MemoryModel>()}\",\n            OperandKind.MemorySemantics => $\"{ToEnum<Specification.MemorySemanticsMask>()}\",\n            OperandKind.AccessQualifier => $\"{ToEnum<Specification.AccessQualifier>()}\",\n            OperandKind.AddressingModel => $\"{ToEnum<Specification.AddressingModel>()}\",","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Spirv/SpvLiteral.cs#L150-L186","documentation":"SpvLiteral.To<T>() converts the literal operand's raw words into a requested managed type T. If T does not match any of the explicitly supported literal shapes (the tmp is not a recognized literal type), the method throws NotImplementedException naming the requested type. Only conversions compiled into SpvLiteral are supported.","triggerScenarios":"Calling operand.To<SomeType>() where SomeType is not one of the handled literal types (e.g. To<string>, To<SomeCustomStruct>, or an unlisted LiteralArray element type), even though the operand itself parsed fine.","commonSituations":"Requesting a friendly .NET type for a literal the library has no mapping for (e.g. LiteralContextualWord or unusual LiteralArray tuple shapes); assuming To<T> is generic over all SPIR-V literal kinds.","solutions":["Use the concrete literal type returned by the operand's Kind and decode Words yourself","Add a conversion branch for the missing type in SpvLiteral.To<T> and Unsafe.As to it","Cast via an intermediate supported type (e.g. int or (int,int) pairs) and reinterpret","Check SpvLiteral source for the supported type list before choosing T"],"exampleFix":"// before\nvar value = operand.To<MyVector4>();\n// after\nvar pairs = operand.To<LiteralArray<(int, int)>>();\nvar floats = pairs.Items.Select(p => BitConverter.Int32BitsToSingle(p.Item1)).ToArray();","handlingStrategy":"type-guard","validationCode":"if (operand.Kind is not (OperandKind.LiteralInteger or OperandKind.LiteralNumber or OperandKind.LiteralString))\n    throw new NotSupportedException($\"Kind {operand.Kind} has no To<T> mapping\");","typeGuard":"bool IsConvertible<T>(SpvLiteral lit) => lit is not null && SupportedLiteralTypes.Contains(typeof(T));","tryCatchPattern":"try { return operand.To<T>(); }\ncatch (NotImplementedException ex)\n{\n    logger.LogWarning(ex, \"No To<T> mapping for {Type}\", typeof(T));\n    return DecodeManually(operand.Words);\n}","preventionTips":["Check SpvLiteral source for the supported T list before calling","Decode unusual literal kinds from Words directly","Add a To<T> branch and test for each literal kind you use"],"tags":["spirv","conversion","not-implemented"],"backgroundTag":"method-not-implemented","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"}