stride3d/stride · error · InvalidOperationException

ShaderSource [ ] is not supported (Only ShaderMixinSource…

Error message

ShaderSource [{0}] is not supported (Only ShaderMixinSource and ShaderClassSource)

What it means

ShaderMixinContext.Mixin throws InvalidOperationException with message 'ShaderSource [{0}] is not supported (Only ShaderMixinSource and ShaderClassSource)' when a ShaderSource type other than ShaderMixinSource, ShaderClassSource, or ShaderMixinGeneratorSource is passed. The mixin pipeline only knows how to expand these three kinds of shader sources.

Solutions

  1. Convert the source to a ShaderClassSource or ShaderMixinSource before mixing
  2. Handle ShaderArraySource by iterating its entries and mixing each one
  3. Extend/patch the mixin handling if a new source type must be supported

Example fix

// before
context.Mixin(tree, shaderArraySource); // unsupported type
// after
foreach (var source in shaderArraySource.Values)
    context.Mixin(tree, source); // mix each supported source individually
Defensive patterns

Strategy: validation

Validate before calling

if (source is not (ShaderMixinSource or ShaderClassSource or ShaderMixinGeneratorSource))
    throw new InvalidOperationException($"Unsupported shader source type {source.GetType().Name}");

Type guard

static bool IsMixable(ShaderSource s) => s is ShaderMixinSource or ShaderClassSource or ShaderMixinGeneratorSource;

Try / catch

try { context.Mixin(tree, source); }
catch (InvalidOperationException ex) when (ex.Message.Contains("is not supported")) { logger.LogError(ex, "Unsupported ShaderSource type"); throw; }

Prevention

When it happens

Trigger: Calling ctx.Mixin(mixinTree, someShaderSource) with e.g. a raw ShaderSource, ShaderArraySource, or a custom ShaderSource subclass the mixin system does not handle.

Common situations: Custom shader source types from extensions; passing output of another compilation stage unchanged; upgrades where a new ShaderSource subtype isn't yet handled by the mixin pipeline.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at sources/shaders/Stride.Shaders.Effects/ShaderMixinContext.cs:305

            {
                return;
            }

            if (shaderSource is ShaderMixinSource shaderMixinSource)
            {
                mixinTree.CloneFrom(shaderMixinSource);
            }
            else if (shaderSource is ShaderClassCode shaderClassCode)
            {
                mixinTree.Mixins.Add(shaderClassCode);
            }
            else if (shaderSource is ShaderMixinGeneratorSource mixinGeneratorSource)
            {
                Mixin(mixinTree, mixinGeneratorSource.Name);
            }
            else
            {
                throw new InvalidOperationException("ShaderSource [{0}] is not supported (Only ShaderMixinSource and ShaderClassSource)".ToFormat(shaderSource.GetType()));
            }

            // If we are mixin a shader source that has an attached discard, don't proceed further
            if (shaderSource.Discard)
            {
                Discard();
            }
        }

        // Helpers, until we get rid of ParameterCollection
        private void Set<T>(ParameterCollection parameterCollection, PermutationParameterKey<T> key, T value)
        {
            parameterCollection.Set(key, value);
        }

        private T Get<T>(ParameterCollection parameterCollection, PermutationParameterKey<T> key)
        {
            return parameterCollection.Get(key);

View on GitHub (pinned to 96fad776d2)