stride3d/stride · error · InvalidOperationException

Could not compile shader. See error messages:

Error message

Could not compile shader. See error messages: 

What it means

EffectSystem.CheckResult throws InvalidOperationException when the shader compiler result contains errors, aggregating the compiler log text into the message. It indicates a Stride shader (.sdsl/.sdfx) failed to compile.

Solutions

  1. Read the appended compilerResult.ToText() in the message for the actual compiler errors.
  2. Fix the shader source (syntax, missing mixins, invalid keys) listed in the log.
  3. Ensure effect shaders are present and registered in the build (check .sdsl files compile in the editor).
  4. Re-run with a matching graphics API profile the shader targets.

Example fix

// shader before
shader MyShader : ShaderBase
{
  compute computeMain()
  {
    undefinedFunction(); // error reported here
  }
}
// after: replace with a valid mixin call or define the function
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate: ensure the effect name resolves to an existing .sdsl/.sdfx shader in the project
bool ShaderExists(string name) => System.IO.File.Exists(System.IO.Path.Combine(shaderSourcePath, name + ".sdsl")) || System.IO.File.Exists(System.IO.Path.Combine(shaderSourcePath, name + ".sdfx"));

Try / catch

try { var effect = effectSystem.LoadEffect("MyEffect"); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Could not compile shader"))
{
    // ex.Message contains the full compiler log after the prefix
    log.Error(ex.Message.Substring("Could not compile shader. See error messages: ".Length));
}

Prevention

When it happens

Trigger: Loading an effect whose shader source has syntax/semantic errors, uses missing mixins/compositions, or fails platform-specific compilation; called from LoadEffect/CreateEffect.

Common situations: Typo in a shader composition name, missing shader class, invalid keyword usage, or a shader that fails on a specific graphics API after working on another.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/ea7731612f883f49. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Rendering/Rendering/EffectSystem.cs:178

                // is already waiting on the result
                var result = bytecode.Task.ContinueWith(
                    x => CreateEffect(effectName, x.Result, compilerResult),
                    scheduler: TaskScheduler.Default);
                return result;
            }
            else
            {
                return CreateEffect(effectName, bytecode.WaitForResult(), compilerResult);
            }
        }

        // TODO: THIS IS JUST A WORKAROUND, REMOVE THIS

        private static void CheckResult(LoggerResult compilerResult)
        {
            if (compilerResult.HasErrors)
            {
                throw new InvalidOperationException("Could not compile shader. See error messages: " + compilerResult.ToText());
            }
        }

        private Effect CreateEffect(string effectName, EffectBytecodeCompilerResult effectBytecodeCompilerResult, CompilerResults compilerResult)
        {
            Effect effect;
            lock (cachedEffects)
            {
                if (!isInitialized)
                    throw new ObjectDisposedException(nameof(EffectSystem), "EffectSystem has been disposed. This Effect compilation has been cancelled.");

                if (effectBytecodeCompilerResult.CompilationLog.HasErrors)
                {
                    // Unregister result
                    // TODO: Should we keep it so that failure never change?
                    if (earlyCompilerCache.TryGetValue(effectName, out List<CompilerResults> effectCompilerResults))
                    {
                        effectCompilerResults.Remove(compilerResult);

View on GitHub (pinned to 96fad776d2)