stride3d/stride · error · ArgumentNullException
device
Error message
device
What it means
Effect.InitializeFrom throws ArgumentNullException with parameter name "device" when a null GraphicsDevice is passed while constructing or initializing an Effect from EffectBytecode. The effect needs a valid device to initialize its internal resource bindings.
Solutions
- Ensure a valid, initialized GraphicsDevice is created before constructing any Effect.
- Fix initialization order: create the device first, then load effects (e.g. in Game.LoadContent).
- Add null checks/asserts upstream so the device is resolved before reaching Effect construction.
Example fix
// before var effect = new Effect(null, bytecode); // after var effect = new Effect(graphicsDevice, bytecode); // graphicsDevice must be non-null
Defensive patterns
Strategy: validation
Validate before calling
if (graphicsDevice == null)
throw new InvalidOperationException("GraphicsDevice must be initialized before creating an Effect");
var effect = new Effect(graphicsDevice, bytecode); Type guard
bool HasValidDevice(GraphicsDevice d) => d is { IsDisposed: false }; Try / catch
try { effect = new Effect(device, bytecode); }
catch (ArgumentNullException ex) { log.Error(ex, "Effect created with null device — check init order"); throw; } Prevention
- Create effects only after GraphicsDevice is fully initialized (e.g. in LoadContent).
- Avoid storing the device in a nullable field read during construction before assignment.
- Add constructor guards in wrappers around Effect creation.
When it happens
Trigger: Calling new Effect(device, bytecode) or effect.InitializeFrom(device, bytecode) with a null device — e.g. a GraphicsDevice field not yet assigned in a constructor, or deserialization producing a null device.
Common situations: Game code creating effects before the GraphicsService/Game instance is ready; dependency-injection ordering issues where the device property is still null; unit tests passing null.
Related errors
- bytecode
- ArgumentNullException: data
- ArgumentNullException: heightmap
- ArgumentNullException: paramName
- Cannot add a null component
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/8485978a4aa384a5.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Effects/Effect.cs:49
/// <summary>
/// Initializes a new instance of the <see cref="Effect"/> class.
/// </summary>
/// <param name="device">The device.</param>
/// <param name="bytecode">The bytecode.</param>
/// <param name="usedParameters">The parameters used to create this shader (from a sdfx).</param>
/// <exception cref="System.ArgumentNullException">
/// device
/// or
/// bytecode
/// </exception>
public Effect(GraphicsDevice device, EffectBytecode bytecode)
{
InitializeFrom(device, bytecode);
}
internal void InitializeFrom(GraphicsDevice device, EffectBytecode bytecode)
{
if (device == null) throw new ArgumentNullException("device");
if (bytecode == null) throw new ArgumentNullException("bytecode");
this.graphicsDeviceDefault = device;
this.bytecode = bytecode;
Initialize();
}
/// <summary>
/// Gets the bytecode.
/// </summary>
/// <value>The bytecode.</value>
public EffectBytecode Bytecode
{
get
{
return bytecode;
}
}View on GitHub (pinned to 96fad776d2)