{"record":{"id":"f4a37bb0760bb15d","repo":"dotnet/BenchmarkDotNet","slug":"method-methodtocall-should-be-static-method","errorCode":null,"errorMessage":"Method {methodToCall} should be static method.","messagePattern":"Method (.+?) should be static method\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Helpers/Reflection.Emit/IlGeneratorCallExtensions.cs","lineNumber":14,"sourceCode":"using System.Reflection;\nusing System.Reflection.Emit;\n\nnamespace BenchmarkDotNet.Helpers.Reflection.Emit\n{\n    internal static class IlGeneratorCallExtensions\n    {\n        public static void EmitStaticCall(\n            this ILGenerator ilBuilder,\n            MethodInfo methodToCall,\n            params LocalBuilder[] argLocals)\n        {\n            if (!methodToCall.IsStatic)\n                throw new ArgumentException($\"Method {methodToCall} should be static method.\");\n\n            EmitCallCore(ilBuilder, null, methodToCall, argLocals);\n        }\n\n        public static void EmitInstanceCallThisValueOnStack(\n            this ILGenerator ilBuilder,\n            LocalBuilder optionalLocalThis,\n            MethodInfo methodToCall,\n            params LocalBuilder[] argLocals) =>\n            EmitInstanceCallThisValueOnStack(ilBuilder, optionalLocalThis, methodToCall, argLocals, false);\n\n        public static void EmitInstanceCallThisValueOnStack(\n            this ILGenerator ilBuilder,\n            LocalBuilder? optionalLocalThis,\n            MethodInfo methodToCall,\n            IEnumerable<LocalBuilder> argLocals,\n            bool forceDirectCall = false)\n        {","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Helpers/Reflection.Emit/IlGeneratorCallExtensions.cs#L1-L32","documentation":"IlGeneratorCallExtensions.EmitStaticCall is an internal helper used by BenchmarkDotNet's IL emission for generated benchmark assemblies. It requires the supplied MethodInfo to be static; otherwise it throws ArgumentException. End users do not call it directly-it runs during benchmark assembly code generation.","triggerScenarios":"The internal IL emitter is asked to emit a static call (call opcode) for a MethodInfo whose IsStatic is false, i.e. an instance method was supplied where a static method was expected.","commonSituations":"A mismatch inside BenchmarkDotNet's code generator (e.g. awaiting/calling an instance helper as if static), almost always indicating a library bug rather than user misconfiguration. Encountered with unusual benchmark method shapes (async iterators, ref returns, etc.).","solutions":["Simplify the benchmark method signature to a common supported shape and re-run.","Update BenchmarkDotNet to the latest version where codegen edge cases are fixed.","If reproducible on the current version, file a BenchmarkDotNet issue with the benchmark that triggers code generation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { runner.Run(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"should be static method\")) { /* simplify benchmark, report issue */ }","preventionTips":["Use standard benchmark method shapes supported by the codegen.","Keep BenchmarkDotNet current to pick up codegen fixes.","Report reproducible codegen ArgumentExceptions with a minimal benchmark."],"tags":["il-emit","reflection","internal","codegen"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}