stride3d/stride · error · ArgumentNullException

Invalid null mixin name

Error message

Invalid null mixin name

What it means

ShaderMixinContext.Mixin throws ArgumentNullException("name", "Invalid null mixin name") when the shader name passed to Mixin is null. The name is used to look up a registered IShaderMixinBuilder or to add a ShaderClassSource. The custom message clarifies the mixin name specifically was null.

Solutions

  1. Pass a valid shader class name string to Mixin
  2. Check the composition/source object whose Name is null and fix its initialization
  3. Validate effect/composition definitions before invoking the mixin pipeline

Example fix

// before
context.Mixin(tree, composition.ShaderName); // may be null
// after
if (!string.IsNullOrEmpty(composition.ShaderName))
    context.Mixin(tree, composition.ShaderName);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(name)) throw new InvalidOperationException("Composition has no shader assigned");
context.Mixin(tree, name);

Type guard

static bool HasMixinName(string name) => !string.IsNullOrEmpty(name);

Try / catch

try { context.Mixin(tree, name); }
catch (ArgumentNullException ex) when (ex.ParamName == "name") { throw new InvalidOperationException("Composition slot has no shader assigned", ex); }

Prevention

When it happens

Trigger: Calling ctx.Mixin(mixinTree, null), e.g. when the mixin name comes from ShaderMixinGeneratorSource.Name or a composition entry that was not initialized.

Common situations: A composition slot with no assigned shader; deserialized effect definitions with missing shader names; ShaderClassSource names typed incorrectly leading to null resolution upstream.

Related errors


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

Appendix: source

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

            {
                var mixin = mixinParent.Mixins[i];
                if (mixin.ClassName == name)
                {
                    mixinParent.Mixins.RemoveAt(i);
                }
            }
        }

        /// <summary>
        /// Mixins a <see cref="ShaderMixinSource" /> into the specified mixin tree.
        /// </summary>
        /// <param name="mixinTree">The mixin tree.</param>
        /// <param name="name">The name.</param>
        public void Mixin(ShaderMixinSource mixinTree, string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name", "Invalid null mixin name");
            }

            IShaderMixinBuilder builder;
            if (!registeredBuilders.TryGetValue(name, out builder))
            {
                // Else simply add the name of the shader
                mixinTree.Mixins.Add(new ShaderClassSource(name));
            }
            else if (builder != null)
            {
                builder.Generate(mixinTree, this);
            }
        }

        /// <summary>
        /// Mixins a <see cref="ShaderClassSource" /> identified by its name/generic parameters into the specified mixin tree.
        /// </summary>
        /// <param name="mixinTree">The mixin tree.</param>

View on GitHub (pinned to 96fad776d2)