stride3d/stride · error · ArgumentException

Unsupported ShaderSource type

Error message

Unsupported ShaderSource type [{0}]. Supporting only ShaderMixinSource/sdfx, ShaderClassSource

What it means

EffectCompilerBase.Compile validates that the incoming ShaderSource is a ShaderMixinSource or ShaderClassSource (which it can convert into a mixin). Any other ShaderSource implementation leaves mixinToCompile null and this ArgumentException is thrown. The library only supports those two shader source representations for effect compilation.

Solutions

  1. Convert the source into a ShaderMixinSource (set Name and add the mixin parts) before calling Compile.
  2. If you have a ShaderClassSource, pass it directly — it is wrapped into a ShaderMixinSource automatically.
  3. Check the concrete type of the object you pass with GetType() and fix the construction site.
  4. If you need a custom ShaderSource type, pre-flatten it into mixin/class sources instead of subclassing ShaderSource.

Example fix

// before
shaderCompiler.Compile(myCustomShaderSource, parameters);
// after
var mixin = new ShaderMixinSource { Name = "MyShader" };
mixin.Mixins.Add(new ShaderClassSource("MyShader"));
shaderCompiler.Compile(mixin, parameters);
Defensive patterns

Strategy: type-guard

Validate before calling

if (source is not (ShaderMixinSource or ShaderClassSource)) throw new ArgumentException($"Cannot compile {source?.GetType().Name}; use ShaderMixinSource or ShaderClassSource");

Type guard

bool IsCompilableShaderSource(ShaderSource s) => s is ShaderMixinSource || s is ShaderClassSource;

Try / catch

try { compiler.Compile(source, parameters); } catch (ArgumentException ex) when (ex.Message.Contains("Unsupported ShaderSource type")) { /* convert to ShaderMixinSource and retry */ }

Prevention

When it happens

Trigger: Calling EffectCompilerBase.Compile with a ShaderSource that is neither ShaderMixinSource nor ShaderClassSource — e.g. a custom IShaderSource implementation, a ShaderSourceStoryboard/parse-tree source, or a deserialized object of the wrong concrete type.

Common situations: Custom shader-source subclasses written against an older Stride API; passing an effect 'description' object instead of a compiled source; versions where additional ShaderSource types were accepted being replaced by mixin-only compilation.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at sources/shaders/Stride.Shaders.Effects/Compiler/EffectCompilerBase.cs:60

            if (shaderMixinGeneratorSource != null)
            {
                mixinToCompile = ShaderMixinManager.Generate(shaderMixinGeneratorSource.Name, compilerParameters);
            }
            else
            {
                mixinToCompile = shaderSource as ShaderMixinSource;
                var shaderClassSource = shaderSource as ShaderClassCode;

                if (shaderClassSource != null)
                {
                    mixinToCompile = new ShaderMixinSource { Name = shaderClassSource.ClassName };
                    mixinToCompile.Mixins.Add(shaderClassSource);
                }

                if (mixinToCompile == null)
                {
                    throw new ArgumentException("Unsupported ShaderSource type [{0}]. Supporting only ShaderMixinSource/sdfx, ShaderClassSource", "shaderSource");
                }
                if (string.IsNullOrEmpty(mixinToCompile.Name))
                {
                    throw new ArgumentException("ShaderMixinSource must have a name", "shaderSource");
                }
            }

            // Compile the whole mixin tree
            var compilerResults = new CompilerResults { Module = $"EffectCompile [{mixinToCompile.Name}]" };
            var effectInputHash = ShaderMixinObjectId.Compute(mixinToCompile, compilerParameters.EffectParameters);
            var bytecode = Compile(mixinToCompile, effectParameters: compilerParameters.EffectParameters, compilerParameters, effectInputHash);

            // Since bytecode.Result is a struct, we check if any of its member has been set to know if it's valid
            if (bytecode.Result.CompilationLog is not null || bytecode.Task is not null)
            {
                bytecode.Result.CompilationLog?.CopyTo(compilerResults);
                compilerResults.Bytecode = bytecode;
                compilerResults.SourceParameters = new CompilerParameters(compilerParameters);

View on GitHub (pinned to 96fad776d2)