StockSharp/StockSharp · error · ArgumentOutOfRangeException

parameters

Error message

parameters

What it means

ArgumentOutOfRangeException with ParamName="parameters", thrown by GpuLunarPhaseCalculator.Calculate at `if (parameters.Length == 0) throw new ArgumentOutOfRangeException(nameof(parameters))` (Algo.Gpu/Indicators/GpuLunarPhaseCalculator.cs:49). Although the lunar-phase kernel itself is parameterless (no params buffer in the kernel signature), the method still enforces a non-empty GpuLunarPhaseParams[] as a consistency precondition for the series/result grid; an empty array is rejected before launch.

Source

Thrown at Algo.Gpu/Indicators/GpuLunarPhaseCalculator.cs:49

	/// </summary>
	/// <param name="context">ILGPU context.</param>
	/// <param name="accelerator">ILGPU accelerator.</param>
	public GpuLunarPhaseCalculator(Context context, Accelerator accelerator)
		: base(context, accelerator)
	{
		_kernel = Accelerator.LoadAutoGroupedStreamKernel<Index3D, ArrayView<GpuCandle>, ArrayView<GpuIndicatorResult>, ArrayView<int>, ArrayView<int>>(LunarPhaseParamsSeriesKernel);
	}

	/// <inheritdoc />
	public override GpuIndicatorResult[][][] Calculate(GpuCandle[][] candlesSeries, GpuLunarPhaseParams[] parameters)
	{
		ArgumentNullException.ThrowIfNull(candlesSeries);
		ArgumentNullException.ThrowIfNull(parameters);

		if (candlesSeries.Length == 0)
			throw new ArgumentOutOfRangeException(nameof(candlesSeries));
		if (parameters.Length == 0)
			throw new ArgumentOutOfRangeException(nameof(parameters));

		var seriesCount = candlesSeries.Length;

		// Flatten input
		var totalSize = 0;
		var seriesOffsets = new int[seriesCount];
		var seriesLengths = new int[seriesCount];

		for (var s = 0; s < seriesCount; s++)
		{
			seriesOffsets[s] = totalSize;
			var len = candlesSeries[s]?.Length ?? 0;
			seriesLengths[s] = len;
			totalSize += len;
		}

		var flatCandles = new GpuCandle[totalSize];
		var maxLen = 0;

View on GitHub (pinned to 601a191de6)

Solutions

  1. Ensure parameters.Length >= 1 before calling; skip or throw a domain exception otherwise.
  2. Provide a default/placeholder GpuLunarPhaseParams when none are supplied.
  3. Align the validation with actual usage: if the params array is genuinely unused by this kernel, relax the guard or document why one entry is still required.

Example fix

// before
var results = calc.Calculate(candlesSeries, parameters);

// after
if (parameters is null || parameters.Length == 0)
    throw new InvalidOperationException("At least one LunarPhase parameter set is required.");
var results = calc.Calculate(candlesSeries, parameters);
Defensive patterns

Strategy: validation

Validate before calling

if (parameters is null || parameters.Length == 0)
    throw new InvalidOperationException("At least one LunarPhase parameter set is required.");
var results = calc.Calculate(candlesSeries, parameters);

Type guard

static bool IsValidParams(GpuLunarPhaseParams[] p) => p is not null && p.Length > 0;

Try / catch

try { var r = calc.Calculate(candlesSeries, parameters); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "parameters")
{ /* surface config error */ }

Prevention

When it happens

Trigger: Passing an empty GpuLunarPhaseParams[] to Calculate; usually a config source or test that supplies zero parameter entries.

Common situations: Empty `parameters:` in config; UI with no selection forwarded; tests that omit the params array; a generator that filtered out all entries.

Related errors


AI-assisted analysis of StockSharp/StockSharp@601a191de6 (2026-08-13). Data as JSON: /api/errors/7a868a3f3e2f316f. Report an issue: GitHub.