stride3d/stride · error · ArgumentNullException

compilerParameters

Error message

compilerParameters

What it means

The ShaderMixinContext constructor throws ArgumentNullException("compilerParameters") when the ParameterCollection holding compilation parameters is null. The context relies on this collection for all permutation parameters, so it cannot operate without it. This is a fail-fast constructor guard.

Solutions

  1. Pass an empty ParameterCollection instead of null if no parameters exist
  2. Create the ParameterCollection before constructing the context
  3. Check the parameter-providing code path for null returns

Example fix

// before
var ctx = new ShaderMixinContext(tree, null, builders);
// after
var ctx = new ShaderMixinContext(tree, new ParameterCollection(), builders);
Defensive patterns

Strategy: validation

Validate before calling

if (compilerParameters is null) compilerParameters = new ParameterCollection(); // substitute empty collection

Type guard

static bool HasParameters(ParameterCollection p) => p != null;

Try / catch

try { var ctx = new ShaderMixinContext(tree, parameters, builders); }
catch (ArgumentNullException ex) when (ex.ParamName == "compilerParameters") { throw new InvalidOperationException("Compiler parameters must be initialized", ex); }

Prevention

When it happens

Trigger: Calling new ShaderMixinContext(mixinTree, null, registeredBuilders), typically when a default/derived ParameterCollection was never created or a lookup for the compiler parameters returned null.

Common situations: Effect compiler setups that skip parameter collection creation; refactors where the parameters object became nullable; passing a method result that returns null when no parameters are set.

Related errors


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

Appendix: source

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

        private string compositionString = null;

        private readonly ShaderMixinSource currentMixinSourceTree;

        /// <summary>
        /// Initializes a new instance of the <see cref="ShaderMixinContext" /> class.
        /// </summary>
        /// <param name="mixinTree">The mixin tree.</param>
        /// <param name="compilerParameters">The default property container.</param>
        /// <param name="registeredBuilders">The registered builders.</param>
        /// <exception cref="System.ArgumentNullException">compilerParameters
        /// or
        /// registeredBuilders</exception>
        public ShaderMixinContext(ShaderMixinSource mixinTree, ParameterCollection compilerParameters, Dictionary<string, IShaderMixinBuilder> registeredBuilders)
        {
            if (mixinTree == null) throw new ArgumentNullException("mixinTree");
            if (compilerParameters == null)
                throw new ArgumentNullException("compilerParameters");

            if (registeredBuilders == null)
                throw new ArgumentNullException("registeredBuilders");

            // TODO: use a copy of the compilerParameters?
            this.currentMixinSourceTree = mixinTree;
            this.compilerParameters = compilerParameters;
            this.registeredBuilders = registeredBuilders;
            this.parameterCollections = new Stack<ParameterCollection>();
        }

        /// <summary>
        /// Gets or sets the child effect.
        /// </summary>
        /// <value>The child effect.</value>
        public string ChildEffectName { get; set; }

        /// <summary>

View on GitHub (pinned to 96fad776d2)