stride3d/stride · error · ArgumentNullException
key
Error message
key
What it means
SetParam<T> throws ArgumentNullException("key") when the PermutationParameterKey<T> used to set a shader parameter is null. The key identifies which composition/permutation parameter receives the value. Fail-fast guard before writing into the parameter collection.
Solutions
- Pass a valid PermutationParameterKey<T> (e.g. MyShaderKeys.TextureCount)
- Confirm the key name matches a declared permutation key on the target shader
- Guard against null keys resolved by name before calling SetParam
Example fix
// before
context.SetParam(ResolveKey("Color"), value); // ResolveKey may return null
// after
var key = ResolveKey("Color");
if (key != null) { context.SetParam(key, value); } Defensive patterns
Strategy: validation
Validate before calling
if (key is null) throw new InvalidOperationException("Permutation key not found");
context.SetParam(key, value); Type guard
static bool IsValidKey<T>(PermutationParameterKey<T> k) => k != null;
Try / catch
try { context.SetParam(key, value); }
catch (ArgumentNullException) { logger.LogWarning("Skipped SetParam for unknown key"); } Prevention
- Use statically-typed key members from the shader class instead of name lookups
- Validate resolved keys against declared permutation keys
- Add unit tests covering parameter name changes
When it happens
Trigger: Calling ctx.SetParam<T>(null, value) — commonly when the key comes from a cache/lookup that returned null for an unknown parameter name.
Common situations: Renamed or removed permutation keys after shader refactors; dynamically resolved keys where the name doesn't match any declared key.
Related errors
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/382ec39a7f6db743.
Report an issue: GitHub.
Appendix: source
Thrown at sources/shaders/Stride.Shaders.Effects/ShaderMixinContext.cs:166
}
return null;
}
private PermutationParameterKey<T> GetComposeKey<T>(PermutationParameterKey<T> key)
{
if (compositionString == null)
{
return key;
}
key = key.ComposeWith(compositionString);
return key;
}
public void SetParam<T>(PermutationParameterKey<T> key, T value)
{
if (key == null)
throw new ArgumentNullException("key");
var propertyContainer = parameterCollections.Count > 0 ? parameterCollections.Peek() : compilerParameters;
Set(propertyContainer, key, value);
}
/// <summary>
/// Removes the specified mixin from this instance.
/// </summary>
/// <param name="mixinTree">The mixin tree.</param>
/// <param name="name">The name.</param>
public void RemoveMixin(ShaderMixinSource mixinTree, string name)
{
var mixinParent = mixinTree;
for (int i = mixinParent.Mixins.Count - 1; i >= 0; i--)
{
var mixin = mixinParent.Mixins[i];
if (mixin.ClassName == name)
{View on GitHub (pinned to 96fad776d2)