{"record":{"id":"94c6c5e34f7d5450","repo":"dotnet/BenchmarkDotNet","slug":"can-not-emit-base-call-for-constructorbuilder","errorCode":null,"errorMessage":"Can not emit base call for {constructorBuilder}","messagePattern":"Can not emit base call for (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Helpers/Reflection.Emit/IlGeneratorStatementExtensions.cs","lineNumber":11,"sourceCode":"using System.Reflection;\nusing System.Reflection.Emit;\n\nnamespace BenchmarkDotNet.Helpers.Reflection.Emit\n{\n    internal static class IlGeneratorStatementExtensions\n    {\n        public static void EmitCallBaseParameterlessCtor(this ILGenerator ilGenerator, ConstructorBuilder constructorBuilder)\n        {\n            if (constructorBuilder.IsStatic)\n                throw new ArgumentException($\"Can not emit base call for {constructorBuilder}\");\n            if (constructorBuilder.DeclaringType == null)\n                throw new ArgumentException($\"The {nameof(constructorBuilder)} should have non-null {nameof(constructorBuilder.DeclaringType)}.\");\n\n            /*\n                IL_0000: ldarg.0\n                IL_0001: call instance void [BenchmarkDotNet]BenchmarkDotNet.Samples.SampleBenchmark::.ctor()\n            */\n            var baseCtor = constructorBuilder.DeclaringType.BaseType?.GetConstructor([]);\n            if (baseCtor == null)\n                throw new ArgumentException(\n                    $\"Base type of {constructorBuilder.DeclaringType} has no public parameterless constructor.\");\n\n            ilGenerator.Emit(OpCodes.Ldarg_0);\n            ilGenerator.Emit(OpCodes.Call, baseCtor);\n        }\n\n        public static void EmitCtorReturn(this ILGenerator ilBuilder, ConstructorBuilder methodBuilder)\n        {","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Helpers/Reflection.Emit/IlGeneratorStatementExtensions.cs#L1-L29","documentation":"IlGeneratorStatementExtensions.EmitCallBaseParameterlessCtor (internal) refuses to emit a base-constructor call for a static ConstructorBuilder: a static constructor has no base instance ctor to call. It throws ArgumentException. This is an internal precondition of generated-type construction.","triggerScenarios":"The emitter is asked to emit a base-ctor call for a static ConstructorBuilder, which is semantically invalid.","commonSituations":"Library codegen bug during generation of a benchmark wrapper type; not reachable through normal user configuration.","solutions":["Retry with a standard benchmark class layout (no static constructor edge case).","Upgrade BenchmarkDotNet; report the issue with a reproducible benchmark if it persists."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { runner.Run(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Can not emit base call\")) { /* simplify type layout, report issue */ }","preventionTips":["Avoid static-constructor edge cases in benchmark types.","Keep BenchmarkDotNet current.","Report reproducible constructor-emit errors."],"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"}