{"record":{"id":"8a35dc99ff7557b6","repo":"dotnet/BenchmarkDotNet","slug":"methodtype-method-methodinfo-name-is-generic","errorCode":null,"errorMessage":"{methodType} method {methodInfo.Name} is generic.\\nGeneric {methodType} methods are not supported.","messagePattern":"(.+?) method (.+?) is generic\\.\\\\nGeneric (.+?) methods are not supported\\.","errorType":"exception","errorClass":"InvalidBenchmarkDeclarationException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Running/BenchmarkConverter.cs","lineNumber":277,"sourceCode":"            => benchmarks.Where(benchmark => filters.All(filter => filter.Predicate(benchmark))).ToImmutableArray();\n\n        private static void AssertMethodHasCorrectSignature(string methodType, MethodInfo methodInfo)\n        {\n            if (methodInfo.GetParameters().Any() && !methodInfo.HasAttribute<ArgumentsAttribute>() && !methodInfo.HasAttribute<ArgumentsSourceAttribute>())\n                throw new InvalidBenchmarkDeclarationException($\"{methodType} method {methodInfo.Name} has incorrect signature.\\nMethod shouldn't have any arguments.\");\n        }\n\n        private static void AssertMethodIsAccessible(string methodType, MethodInfo methodInfo)\n        {\n            if (!methodInfo.IsPublic)\n                throw new InvalidBenchmarkDeclarationException($\"{methodType} method {methodInfo.Name} has incorrect access modifiers.\\nMethod must be public.\");\n            /* Moved the code that verifies if DeclaringType of a given MethodInfo (a method) is publicly accessible to CompilationValidator */\n        }\n\n        private static void AssertMethodIsNotGeneric(string methodType, MethodInfo methodInfo)\n        {\n            if (methodInfo.IsGenericMethod)\n                throw new InvalidBenchmarkDeclarationException($\"{methodType} method {methodInfo.Name} is generic.\\nGeneric {methodType} methods are not supported.\");\n        }\n\n        private static object?[] GetValidValues(object?[] values, Type parameterType)\n            => values.Select(value => Map(value, parameterType)).ToArray();\n\n        private static object? Map(object? providedValue, Type type)\n        {\n            if (providedValue == null)\n                return null;\n\n            if (providedValue.GetType().IsArray)\n            {\n                return ArrayParam<IParam>.FromObject(providedValue);\n            }\n            // Usually providedValue contains all needed type information,\n            // but in case of F# enum types in attributes are erased.\n            // We can to restore them from types of arguments and fields.\n            // See also:","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Running/BenchmarkConverter.cs#L259-L295","documentation":"Thrown by AssertMethodIsNotGeneric when a benchmark or lifecycle method is a generic method (IsGenericMethod == true). BenchmarkDotNet cannot generate host code for generic methods because the type arguments cannot be determined at code-generation time. Unlike generic types (which BenchmarkSwitcher can handle via type arguments), generic methods are unsupported.","triggerScenarios":"Declaring [Benchmark] public void Run<T>(T value) or [GlobalSetup] public void Setup<T>() — any method with type parameters annotated with a benchmark attribute.","commonSituations":"Writing a generic benchmark utility method and annotating it with [Benchmark]. Refactoring a helper into a benchmark method while leaving its generic type parameter.","solutions":["Remove the type parameters and make the method non-generic, using a concrete type.","If testing multiple types, create separate non-generic benchmark methods for each type."],"exampleFix":"// before\n[Benchmark]\npublic void Run<T>(T[] data) { /* ... */ }\n\n// after\n[Benchmark]\npublic void Run(int[] data) { /* ... */ }\n\n[Benchmark]\npublic void RunString(string[] data) { /* ... */ }","handlingStrategy":"validation","validationCode":"var method = typeof(MyBench).GetMethod(nameof(MyBench.Run))!;\nif (method.IsGenericMethod)\n    throw new InvalidOperationException($\"{method.Name} is generic and cannot be a benchmark.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never declare generic benchmark methods; use separate concrete methods per type.","If testing multiple types, create distinct [Benchmark] methods or benchmark classes.","Add a validation check in a base test class that scans for generic benchmark methods."],"tags":["benchmark-declaration","generics","method-signature","benchmark-converter"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}