{"record":{"id":"9c534953823003ff","repo":"stride3d/stride","slug":"type-conversion-from-originaltype-to-casttype-failed-during","errorCode":null,"errorMessage":"Type conversion from {originalType} to {castType} failed during conversion (current type: {valueType})","messagePattern":"Type conversion from (.+?) to (.+?) failed during conversion \\(current type: (.+?)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Expressions.cs","lineNumber":614,"sourceCode":"                    break;\n                }\n        }\n\n        if (valueType.GetElementType() != castType.GetElementType())\n        {\n            // Type casting\n            // (process each vector one by one)\n            (int elementSize, var castTypeSameSize) = valueType switch\n            {\n                ScalarType s => (1, (SymbolType)castType.GetElementType()),\n                VectorType s => (s.Size, new VectorType(castType.GetElementType(), s.Size)),\n                _ => throw new NotSupportedException($\"Unsupported type for element-wise cast: {valueType}\"),\n            };\n            for (int i = 0; i < valueCount; ++i)\n            {\n                var rowValue = values[i];\n                if (rowValue == 0)\n                    throw new InvalidOperationException($\"Type conversion from {originalType} to {castType} failed during conversion (current type: {valueType})\");\n\n                var typeCasting = (valueType.GetElementType(), castType.GetElementType()) switch\n                {\n                    // https://learn.microsoft.com/en-us/windows/win32/direct3d9/casting-and-conversion\n                    (ScalarType { Type: Scalar.Float }, ScalarType { Type: Scalar.Int }) => InsertData(new OpConvertFToS(context.GetOrRegister(castTypeSameSize), context.Bound++, rowValue)),\n                    (ScalarType { Type: Scalar.Float }, ScalarType { Type: Scalar.UInt }) => InsertData(new OpConvertFToU(context.GetOrRegister(castTypeSameSize), context.Bound++, rowValue)),\n\n                    (ScalarType { Type: Scalar.Float }, ScalarType { Type: Scalar.Boolean }) => InsertData(new OpFOrdNotEqual(context.GetOrRegister(castTypeSameSize), context.Bound++, rowValue, context.CreateConstantCompositeVectorRepeat(new FloatLiteral(new(32, true, true), 0.0, new()), elementSize).Id)),\n                    (ScalarType { Type: Scalar.Int }, ScalarType { Type: Scalar.Boolean }) => InsertData(new OpINotEqual(context.GetOrRegister(castTypeSameSize), context.Bound++, rowValue, context.CreateConstantCompositeVectorRepeat(new IntegerLiteral(new(32, false, true), 0, new()), elementSize).Id)),\n                    (ScalarType { Type: Scalar.UInt }, ScalarType { Type: Scalar.Boolean }) => InsertData(new OpINotEqual(context.GetOrRegister(castTypeSameSize), context.Bound++, rowValue, context.CreateConstantCompositeVectorRepeat(new IntegerLiteral(new(32, false, false), 0, new()), elementSize).Id)),\n\n                    (ScalarType { Type: Scalar.Int }, ScalarType { Type: Scalar.Float }) => InsertData(new OpConvertSToF(context.GetOrRegister(castTypeSameSize), context.Bound++, rowValue)),\n                    (ScalarType { Type: Scalar.UInt }, ScalarType { Type: Scalar.Float }) => InsertData(new OpConvertUToF(context.GetOrRegister(castTypeSameSize), context.Bound++, rowValue)),\n\n                    (ScalarType { Type: Scalar.Boolean }, ScalarType { Type: Scalar.Int }) => InsertData(new OpSelect(context.GetOrRegister(castTypeSameSize), context.Bound++, rowValue,\n                                                                                                    context.CreateConstantCompositeVectorRepeat(new IntegerLiteral(new(32, false, true), 1, new()), elementSize).Id,\n                                                                                                    context.CreateConstantCompositeVectorRepeat(new IntegerLiteral(new(32, false, true), 0, new()), elementSize).Id)),\n                    (ScalarType { Type: Scalar.Boolean }, ScalarType { Type: Scalar.Float }) => InsertData(new OpSelect(context.GetOrRegister(castTypeSameSize), context.Bound++, rowValue,","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Expressions.cs#L596-L632","documentation":"Thrown by Builder.Expressions.Convert while iterating the value's rows/components during an element-wise cast. A row value id of 0 (the SPIR-V 'no result' sentinel) means a prior expansion/construct step failed to produce a value, so the conversion is aborted with InvalidOperationException.","triggerScenarios":"During Convert, after the type-expansion loop, one of the values[] entries is 0 (uninitialized/unproduced), indicating the expansion from originalType to valueType silently failed.","commonSituations":"Casting composite values (vectors/matrices) where the earlier composite expansion produced no result id; usually a bug in a specific type combination rather than the direct cast arguments.","solutions":["Identify the originalType->castType pair triggering it and simplify the cast in the shader (cast components manually).","Debug Builder.Expressions.cs expansion logic for that type pair to see why values[i] stays 0.","Check Stride issue tracker for the failing cast combination and update the package."],"exampleFix":"// before (shader)\nint2 v = (int2)someComposite;\n// after\nint2 v = int2((int)someComposite.x, (int)someComposite.y);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { result = builder.Convert(table, context, value, castType); }\ncatch (InvalidOperationException e) when (e.Message.StartsWith(\"Type conversion\"))\n{ Log.Error($\"Convert failed: {e.Message}\"); throw; }","preventionTips":["Simplify multi-step composite casts in shaders into explicit per-component steps.","Test shader casts for each type pair used in your project.","Report the failing type pair upstream; it usually indicates an expansion bug."],"tags":["spirv","conversion-failure","internal-error","shader-compilation"],"backgroundTag":"internal-invariant-violation","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"}