{"record":{"id":"52c096ffba8a59df","repo":"dotnet/BenchmarkDotNet","slug":"benchmark-benchmark-name-has-invalid-number-of-a","errorCode":null,"errorMessage":"Benchmark {benchmark.Name} has invalid number of arguments provided by [ArgumentsSource({valuesInfo.source.Name})]! {array.Length} instead of {parameterDefinitions.Length}.","messagePattern":"Benchmark (.+?) has invalid number of arguments provided by \\[ArgumentsSource\\((.+?)\\)\\]! (.+?) instead of (.+?)\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Parameters/SmartParamBuilder.cs","lineNumber":45,"sourceCode":"        internal static ParameterInstances CreateForArguments(MethodInfo benchmark, ParameterDefinition[] parameterDefinitions, (MemberInfo source, object[] values) valuesInfo, int sourceIndex, SummaryStyle summaryStyle)\n        {\n            var unwrappedValue = valuesInfo.values[sourceIndex];\n\n            if (unwrappedValue is object[] array)\n            {\n                Type? firstParamType = benchmark.GetParameters().FirstOrDefault()?.ParameterType;\n                // the user provided object[] for a benchmark accepting a single argument\n                if (parameterDefinitions.Length == 1 && array.Length == 1\n                    && (array[0]?.GetType() == firstParamType || (firstParamType != null && firstParamType.IsStackOnlyWithImplicitCast(array[0])))) // the benchmark that accepts an object[] as argument\n                {\n                    return new ParameterInstances(\n                        [Create(parameterDefinitions, array[0], valuesInfo.source, sourceIndex, argumentIndex: 0, summaryStyle)]);\n                }\n\n                if (parameterDefinitions.Length > 1)\n                {\n                    if (parameterDefinitions.Length != array.Length)\n                        throw new InvalidOperationException($\"Benchmark {benchmark.Name} has invalid number of arguments provided by [ArgumentsSource({valuesInfo.source.Name})]! {array.Length} instead of {parameterDefinitions.Length}.\");\n\n                    return new ParameterInstances(\n                        array.Select((value, argumentIndex) => Create(parameterDefinitions, value, valuesInfo.source, sourceIndex, argumentIndex, summaryStyle)).ToArray());\n                }\n            }\n\n            if (parameterDefinitions.Length == 1)\n            {\n                return new ParameterInstances([Create(parameterDefinitions, unwrappedValue, valuesInfo.source, sourceIndex, argumentIndex: 0, summaryStyle)]);\n            }\n\n            throw new NotSupportedException($\"Benchmark {benchmark.Name} has invalid type of arguments provided by [ArgumentsSource({valuesInfo.source.Name})]. It should be IEnumerable<object[]> or IEnumerable<object>.\");\n        }\n\n        private static ParameterInstance Create(ParameterDefinition[] parameterDefinitions, object value, MemberInfo source, int sourceIndex, int argumentIndex, SummaryStyle summaryStyle)\n        {\n            if (SourceCodeHelper.IsCompilationTimeConstant(value))\n                return new ParameterInstance(parameterDefinitions[argumentIndex], value, summaryStyle);","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Parameters/SmartParamBuilder.cs#L27-L63","documentation":"Thrown by SmartParamBuilder.CreateForArguments when a benchmark method with multiple parameters is fed an object[] from [ArgumentsSource] whose element count does not match the benchmark's parameter count. The check `parameterDefinitions.Length != array.Length` fires inside the branch where the benchmark has more than one parameter and the yielded array does not align.","triggerScenarios":"A benchmark method declared as void Run(int a, int b, int c) with [ArgumentsSource(nameof(Data))] where Data yields object[] arrays of length 2 or 4 instead of 3. Each yielded array must exactly match the parameter count when the method has >1 parameter.","commonSituations":"Adding or removing a parameter from a benchmark method signature but forgetting to update the ArgumentsSource data provider. Returning jagged arrays of inconsistent lengths. Misunderstanding that for multi-parameter benchmarks each yielded item must be an array matching the full signature.","solutions":["Count the benchmark method parameters and ensure every object[] yielded by the source has exactly that length.","Use a helper that constructs each row from named fields to avoid manual array sizing.","If a single object[] argument is intended (benchmark takes object[] as one parameter), ensure only one parameter is declared and the source yields single-element arrays or scalar objects."],"exampleFix":"// before\npublic IEnumerable<object[]> Data() => new[]\n{\n    new object[] { 1, 2 }, // method has 3 params!\n};\n[Benchmark]\n[ArgumentsSource(nameof(Data))]\npublic void Run(int a, int b, int c) { }\n\n// after\npublic IEnumerable<object[]> Data() => new[]\n{\n    new object[] { 1, 2, 3 },\n};","handlingStrategy":"validation","validationCode":"// Verify each ArgumentsSource row matches the benchmark parameter count\nint paramCount = typeof(MyBench).GetMethod(nameof(MyBench.Run))!.GetParameters().Length;\nforeach (var row in Data())\n    if (row.Length != paramCount)\n        throw new InvalidOperationException($\"Row has {row.Length} elements, expected {paramCount}\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write a unit test that asserts every row from the ArgumentsSource matches the method parameter count.","Keep parameter definitions and data sources near each other in the class.","When adding/removing a parameter, grep for the source method and update all rows."],"tags":["benchmark-declaration","arguments-source","parameter-mismatch","invalid-operation"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}