stride3d/stride · error · ArgumentOutOfRangeException

Expecting value >= 0

Error message

Expecting value >= 0

What it means

ProgressStatusEventArgs reports progress with an optional step model; its constructor validates that currentStep is not negative (>= 0) while stepCount must be >= 1. A negative currentStep throws ArgumentOutOfRangeException('Expecting value >= 0').

Solutions

  1. Pass a 0-based currentStep >= 0
  2. Clamp before constructing: Math.Max(0, currentStep)
  3. If progress is unknown, pass stepCount < 1 (e.g. 0) rather than a negative currentStep

Example fix

// before
new ProgressStatusEventArgs("Loading", step - 1, total);
// after
new ProgressStatusEventArgs("Loading", Math.Max(0, step - 1), total);
Defensive patterns

Strategy: validation

Validate before calling

if (currentStep >= 0 && stepCount >= 1)
    OnProgress(new ProgressStatusEventArgs(message, currentStep, stepCount));

Type guard

bool isValidProgress(int current, int total) => current >= 0 && total >= 1;

Try / catch

try { return new ProgressStatusEventArgs(msg, current, total); }
catch (ArgumentOutOfRangeException) { return new ProgressStatusEventArgs(msg, Math.Max(0, current), Math.Max(1, total)); }

Prevention

When it happens

Trigger: new ProgressStatusEventArgs(msg, currentStep, stepCount) with a negative currentStep — e.g. a counter decremented below zero, an index like i-1 at i==0, or parsed progress values that can be negative.

Common situations: Reporting 'unknown progress' by passing negative steps instead of using stepCount < 1 semantics; off-by-one loop reporting (step - 1 on first iteration).

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core/Diagnostics/ProgressStatusEventArgs.cs:31

    /// <param name="message">The message.</param>
    public ProgressStatusEventArgs(string message)
    {
        ArgumentNullException.ThrowIfNull(message);
        Message = message;
        StepCount = 1;
        HasKnownSteps = false;
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="ProgressStatusEventArgs"/> class.
    /// </summary>
    /// <param name="message">The message.</param>
    /// <param name="currentStep">The current step.</param>
    /// <param name="stepCount">The step count.</param>
    public ProgressStatusEventArgs(string message, int currentStep, int stepCount)
    {
        ArgumentNullException.ThrowIfNull(message);
        if (currentStep < 0) throw new ArgumentOutOfRangeException(nameof(currentStep), "Expecting value >= 0");
        if (stepCount < 1) throw new ArgumentOutOfRangeException(nameof(stepCount), "Expecting value >= 1");
        Message = message;
        CurrentStep = currentStep;
        StepCount = stepCount;
        HasKnownSteps = true;
    }

    /// <summary>
    /// Gets or sets the message associated with the progress.
    /// </summary>
    /// <value>The message.</value>
    public string Message { get; }

    /// <summary>
    /// Gets or sets a value indicating whether this instance has known steps (<see cref="CurrentStep"/> and 
    /// <see cref="StepCount"/> are valid).
    /// </summary>
    /// <value><c>true</c> if this instance has known steps; otherwise, <c>false</c>.</value>

View on GitHub (pinned to 96fad776d2)