stride3d/stride · error · ArgumentNullException

ArgumentNullException: paramName

Error message

ArgumentNullException: paramName

What it means

ArgumentCheck.NotNull throws ArgumentNullException when the object variable is null. The exception's ParamName is the provided variableName (defaulting to "The variable"). It is the base guard that NotEmpty, NotWhiteSpace, and Condition also invoke, so a null reaching any of those surfaces as ArgumentNullException paramName.

Solutions

  1. Null-check or null-coalesce the value before calling the guarded API and fail with a descriptive message identifying the actual source
  2. Find which argument is null from the exception's ParamName and fix the initialization or lookup that produced it
  3. Use the DEBUG-only ArgumentCheck variant's equivalent or Debug.Assert during development to catch it earlier
  4. If null is a valid state, do not pass it to this API; branch before the call

Example fix

// before
var asset = session.FindAsset(id); // may be null
session.Delete(asset); // throws ArgumentNullException paramName
// after
var asset = session.FindAsset(id);
if (asset == null)
    throw new KeyNotFoundException($"Asset {id} not found");
session.Delete(asset);
Defensive patterns

Strategy: validation

Validate before calling

if (variable is null)
    throw new ArgumentNullException(nameof(variable), "Value must be initialized before this call");

Type guard

bool HasValue([NotNullWhen(true)] object? o) => o is not null;

Try / catch

try { NotNull(asset, nameof(asset)); }
catch (ArgumentNullException ex) when (ex.ParamName == nameof(asset))
{
    // asset lookup failed; recover or rethrow with context
}

Prevention

When it happens

Trigger: Passing null to any ArgumentCheck-guarded API: NotNull directly, or indirectly when NotEmpty/NotWhiteSpace/Condition receive a null collection/string/predicate (null fails NotNull before the other checks run).

Common situations: An object was not yet initialized (field default null), a lookup (dictionary/FirstOrDefault) returned null and was forwarded, a method parameter of a caller was null and propagated down, or config/ deserialization failed leaving properties null.

Related errors


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

Appendix: source

Thrown at sources/editor/Stride.Core.Assets.Editor/ArgumentCheck.cs:177

            }
        }

        /// <summary>
        /// Checks wether the <paramref name="variable"/> is not <see langword="null"/>.
        /// Otherwise throws an exception.
        /// </summary>
        /// <param name="variable">The value to check.</param>
        /// <param name="variableName">The name of the variable being checked.</param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="variable"/> cannot be <see langword="null"/>.
        /// </exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static void NotNull(object variable, string variableName)
        {
            var paramName = variableName ?? "The variable";
            if (null == variable)
            {
                throw new ArgumentNullException(paramName);
            }
        }

        /// <summary>
        /// Checks wether the <paramref name="variable"/> is not a white-space string.
        /// Otherwise throws an exception.
        /// </summary>
        /// <param name="variable">The value to check.</param>
        /// <param name="variableName">The name of the variable being checked.</param>
        /// <remarks>
        /// Before checking the <paramref name="variable"/>, a call is made to
        /// <see cref="NotNull"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="variable"/> cannot be <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The <paramref name="variable"/> cannot be an empty <see cref="string"/> or consists only of white-space characters.

View on GitHub (pinned to 96fad776d2)