{"record":{"id":"e1b96715a25eaacf","repo":"stride3d/stride","slug":"expecting-value-0-progressstatuseventargs","errorCode":null,"errorMessage":"Expecting value >= 0","messagePattern":"Expecting value >= 0","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Diagnostics/ProgressStatusEventArgs.cs","lineNumber":31,"sourceCode":"    /// <param name=\"message\">The message.</param>\n    public ProgressStatusEventArgs(string message)\n    {\n        ArgumentNullException.ThrowIfNull(message);\n        Message = message;\n        StepCount = 1;\n        HasKnownSteps = false;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"ProgressStatusEventArgs\"/> class.\n    /// </summary>\n    /// <param name=\"message\">The message.</param>\n    /// <param name=\"currentStep\">The current step.</param>\n    /// <param name=\"stepCount\">The step count.</param>\n    public ProgressStatusEventArgs(string message, int currentStep, int stepCount)\n    {\n        ArgumentNullException.ThrowIfNull(message);\n        if (currentStep < 0) throw new ArgumentOutOfRangeException(nameof(currentStep), \"Expecting value >= 0\");\n        if (stepCount < 1) throw new ArgumentOutOfRangeException(nameof(stepCount), \"Expecting value >= 1\");\n        Message = message;\n        CurrentStep = currentStep;\n        StepCount = stepCount;\n        HasKnownSteps = true;\n    }\n\n    /// <summary>\n    /// Gets or sets the message associated with the progress.\n    /// </summary>\n    /// <value>The message.</value>\n    public string Message { get; }\n\n    /// <summary>\n    /// Gets or sets a value indicating whether this instance has known steps (<see cref=\"CurrentStep\"/> and \n    /// <see cref=\"StepCount\"/> are valid).\n    /// </summary>\n    /// <value><c>true</c> if this instance has known steps; otherwise, <c>false</c>.</value>","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Diagnostics/ProgressStatusEventArgs.cs#L13-L49","documentation":"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').","triggerScenarios":"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.","commonSituations":"Reporting 'unknown progress' by passing negative steps instead of using stepCount < 1 semantics; off-by-one loop reporting (step - 1 on first iteration).","solutions":["Pass a 0-based currentStep >= 0","Clamp before constructing: Math.Max(0, currentStep)","If progress is unknown, pass stepCount < 1 (e.g. 0) rather than a negative currentStep"],"exampleFix":"// before\nnew ProgressStatusEventArgs(\"Loading\", step - 1, total);\n// after\nnew ProgressStatusEventArgs(\"Loading\", Math.Max(0, step - 1), total);","handlingStrategy":"validation","validationCode":"if (currentStep >= 0 && stepCount >= 1)\n    OnProgress(new ProgressStatusEventArgs(message, currentStep, stepCount));","typeGuard":"bool isValidProgress(int current, int total) => current >= 0 && total >= 1;","tryCatchPattern":"try { return new ProgressStatusEventArgs(msg, current, total); }\ncatch (ArgumentOutOfRangeException) { return new ProgressStatusEventArgs(msg, Math.Max(0, current), Math.Max(1, total)); }","preventionTips":["Clamp counters that can go negative","Report indeterminate progress via stepCount < 1, not negative currentStep","Check loop bounds before reporting i-1 style steps"],"tags":["progress","argumentoutofrange","events","validation"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}