stride3d/stride · error · ArgumentNullException

bytecode

Error message

bytecode

What it means

Argument-null validation in Effect.InitializeFrom, reached through the Effect(GraphicsDevice, EffectBytecode) constructor: the bytecode parameter is null. An Effect wraps compiled shader bytecode; without bytecode there is nothing to initialize the effect from, so the guard rejects the call (the docs also list a null device as an accepted failure of this initialization path).

Solutions

  1. Verify the bytecode source (effect asset/stream) loads successfully before constructing the Effect.
  2. Rebuild the Stride effects database / shader compilation output so the bytecode asset exists.
  3. Check that deserialization of EffectBytecode returned non-null before calling InitializeFrom.

Example fix

// before
var effect = new Effect(device, EffectBytecode.Load(stream)); // may be null
// after
var bytecode = EffectBytecode.Load(stream) ?? throw new InvalidOperationException("Effect bytecode missing");
var effect = new Effect(device, bytecode);
Defensive patterns

Strategy: validation

Validate before calling

EffectBytecode bytecode = EffectBytecode.Load(stream);
if (bytecode == null)
    throw new InvalidOperationException("Effect bytecode failed to load — check the effect asset exists");
var effect = new Effect(device, bytecode);

Type guard

bool IsValidBytecode(EffectBytecode b) => b is { Data: { Length: > 0 } };

Try / catch

try { effect = new Effect(device, bytecode); }
catch (ArgumentNullException ex) { log.Error(ex, "Null bytecode — effect asset missing or empty"); throw; }

Prevention

When it happens

Trigger: Calling new Effect(device, null) or InitializeFrom(device, bytecode) where bytecode comes from EffectBytecode.Load/serialization and returned null — e.g. failed resource lookup, missing compiled effect asset, or deserialization of an empty stream.

Common situations: Renamed/moved effect shader source so the compiled bytecode asset is missing; effects database not built; loading effects from a bad/empty stream; asset import pipeline failures.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Graphics/Effects/Effect.cs:50

        /// 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)