{"record":{"id":"53f846b61c56b5eb","repo":"StockSharp/StockSharp","slug":"nameof-parameters-53f846","errorCode":null,"errorMessage":"nameof(parameters)","messagePattern":"nameof\\(parameters\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"warning","filePath":"Algo.Gpu/Indicators/GpuSmaCalculator.cs","lineNumber":65,"sourceCode":"\t/// <param name=\"accelerator\">ILGPU accelerator.</param>\n\tpublic GpuSmaCalculator(Context context, Accelerator accelerator)\n\t\t: base(context, accelerator)\n\t{\n\t\t_paramsSeriesKernel = Accelerator.LoadAutoGroupedStreamKernel\n\t\t\t<Index3D, ArrayView<GpuCandle>, ArrayView<GpuIndicatorResult>, ArrayView<int>, ArrayView<int>, ArrayView<GpuSmaParams>>(SmaParamsSeriesKernel);\n\t}\n\n\t/// <inheritdoc />\n\tpublic override GpuIndicatorResult[][][] Calculate(GpuCandle[][] candlesSeries, GpuSmaParams[] parameters)\n\t{\n\t\tArgumentNullException.ThrowIfNull(candlesSeries);\n\t\tArgumentNullException.ThrowIfNull(parameters);\n\n\t\tif (candlesSeries.Length == 0)\n\t\t\tthrow new ArgumentOutOfRangeException(nameof(candlesSeries));\n\n\t\tif (parameters.Length == 0)\n\t\t\tthrow new ArgumentOutOfRangeException(nameof(parameters));\n\n\t\tvar seriesCount = candlesSeries.Length;\n\n\t\t// Flatten input\n\t\tvar totalSize = 0;\n\t\tvar seriesOffsets = new int[seriesCount];\n\t\tvar seriesLengths = new int[seriesCount];\n\n\t\tfor (var s = 0; s < seriesCount; s++)\n\t\t{\n\t\t\tseriesOffsets[s] = totalSize;\n\t\t\tvar len = candlesSeries[s]?.Length ?? 0;\n\t\t\tseriesLengths[s] = len;\n\t\t\ttotalSize += len;\n\t\t}\n\n\t\tvar flatCandles = new GpuCandle[totalSize];\n\t\tvar maxLen = 0;","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/StockSharp/StockSharp/blob/601a191de678bff83da28b14828f8885214ca71c/Algo.Gpu/Indicators/GpuSmaCalculator.cs#L47-L83","documentation":"The GpuSmaCalculator.Calculate method throws ArgumentOutOfRangeException(nameof(parameters)) when the parameters array is empty. This is the wrong exception type for empty-collection validation — ArgumentOutOfRangeException is intended for scalar values outside an allowed range. The idiomatic .NET choice is ArgumentException with a message. The single-argument constructor provides no descriptive error text.","triggerScenarios":"Calling GpuSmaCalculator.Calculate(candlesSeries, parameters) where parameters is Array.Empty<GpuSmaParams>(). Null guard passes; parameters.Length == 0 throws at line 65.","commonSituations":"Dynamic param-set builders filtering to zero entries. Deserialization producing empty arrays. Test edge cases. Config-driven selection with no SMA variant active.","solutions":["Replace ArgumentOutOfRangeException with ArgumentException and a descriptive message: throw new ArgumentException(\"Parameters array must not be empty.\", nameof(parameters));","Validate the params collection upstream and skip the call when empty.","Document the non-empty contract on the base class method."],"exampleFix":"// before\nif (parameters.Length == 0)\n    throw new ArgumentOutOfRangeException(nameof(parameters));\n\n// after\nif (parameters.Length == 0)\n    throw new ArgumentException(\"Parameters array must not be empty.\", nameof(parameters));","handlingStrategy":"validation","validationCode":"// Validate before calling Calculate to avoid the exception entirely\nif (parameters is null || parameters.Length == 0)\n{\n    return Array.Empty<GpuIndicatorResult[][]>();\n}\nvar results = calculator.Calculate(candlesSeries, parameters);","typeGuard":"static bool IsValidParams<TParam>(TParam[] parameters) where TParam : struct\n    => parameters is { Length: > 0 };","tryCatchPattern":null,"preventionTips":["Always check parameters.Length > 0 before calling Calculate.","Skip the call when no parameter sets are selected.","Unit-test the empty-params boundary case."],"tags":["argument-validation","exception-type","gpu-indicator","csharp","api-design"],"backgroundTag":null,"analyzedSha":"601a191de678bff83da28b14828f8885214ca71c","analyzedAt":"2026-08-13T20:43:24.460Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}