{"record":{"id":"64ff91b1b08ba49a","repo":"stride3d/stride","slug":"could-not-load-shader-classname","errorCode":null,"errorMessage":"Could not load shader [{className}]","messagePattern":"Could not load shader \\[(.+?)\\]","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Class.cs","lineNumber":928,"sourceCode":"        for (var index = 0; index < shader.Count; index++)\n        {\n            var i = shader[index];\n            if (i.Op == Op.OpGenericParameterSDSL && (OpGenericParameterSDSL)i is { } genericParameter)\n            {\n                generics.Add(genericParameter.ResultId);\n                SetOpNop(i.Data.Memory.Span);\n            }\n        }\n\n        return generics;\n    }\n\n    public static ShaderBuffers GetOrLoadShader(IExternalShaderLoader shaderLoader, string className, ReadOnlySpan<ShaderMacro> defines, out ObjectId hash, out bool isFromCache)\n    {\n        //Console.WriteLine($\"[Shader] Requesting non-generic class {className}\");\n\n        if (!shaderLoader.LoadExternalBuffer(className, defines, out var buffer, out hash, out isFromCache))\n            throw new InvalidOperationException($\"Could not load shader [{className}]\");\n\n        //if (!isFromCache)\n        //    Console.WriteLine($\"[Shader] Loading non-generic class {className} for 1st time\");\n\n        return buffer;\n    }\n}\n","sourceCodeStart":910,"sourceCodeEnd":936,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Class.cs#L910-L936","documentation":"SpirvBuilder.GetOrLoadShader asks the IExternalShaderLoader to load a precompiled shader buffer by class name and macro defines. When the loader cannot return a buffer for the requested class, the builder throws InvalidOperationException to abort compilation. It indicates the shader class name or macro combination does not resolve to any loadable external shader.","triggerScenarios":"Calling SpirvBuilder.GetOrLoadShader (directly or via shader compilation) with a className that the external loader does not recognize, or with defines that match no cached/registered shader; LoadExternalBuffer returns false.","commonSituations":"Typo in shader class name passed to a effect/shader reference; shader source not registered with the external loader; mismatched ShaderMacro set so the cache lookup key differs; shader asset missing at runtime/deployment.","solutions":["Verify the className exactly matches a shader class registered with the IExternalShaderLoader (check spelling and namespace)","Ensure the shader source/asset is loaded/registered before GetOrLoadShader is called","Confirm the ShaderMacro defines passed match those used when the shader was compiled/cached","Inspect the loader's LoadExternalBuffer implementation/logging to see why the lookup failed","Check that required shader assets exist in the deployment output directory"],"exampleFix":"// before\nvar buffers = SpirvBuilder.GetOrLoadShader(loader, \"MyShderClass\", defines, out hash, out fromCache);\n// after\nvar buffers = SpirvBuilder.GetOrLoadShader(loader, \"MyShaderClass\", defines, out hash, out fromCache);","handlingStrategy":"validation","validationCode":"// Before compiling, ensure the shader class exists and the loader can resolve it\nif (!shaderLoader.TryResolveShaderClass(className, defines))\n    throw new ArgumentException($\"Unknown shader class '{className}' for defines [{string.Join(\",\", defines.Select(d => d.Name))}]\");","typeGuard":"bool IsKnownShader(IExternalShaderLoader l, string name, ReadOnlySpan<ShaderMacro> defines) => l.LoadExternalBuffer(name, defines, out _, out _, out _);","tryCatchPattern":"try { var buffers = SpirvBuilder.GetOrLoadShader(loader, className, defines, out var hash, out var cached); }\ncatch (InvalidOperationException ex) { Log.Error(ex, \"Shader '{Class}' not loadable with current defines\", className); throw new ShaderCompilationException(className, defines, ex); }","preventionTips":["Keep shader class names in constants/enums instead of raw strings","Register all shader sources with the loader at startup and assert registration in tests","Keep macro defines consistent between build and load sites","Verify shader assets are copied to the output/deployment directory"],"tags":["shader","compilation","not-found","spirv"],"backgroundTag":"resource-not-found","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"}