{"record":{"id":"9acc10107fd3bd62","repo":"dotnet/BenchmarkDotNet","slug":"the-constructorbuilder-should-have-non-null-declar","errorCode":null,"errorMessage":"The constructorBuilder should have non-null DeclaringType.","messagePattern":"The constructorBuilder should have non-null DeclaringType\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Helpers/Reflection.Emit/IlGeneratorStatementExtensions.cs","lineNumber":13,"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        {\n            // IL_0000: ret\n            ilBuilder.Emit(OpCodes.Ret);","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Helpers/Reflection.Emit/IlGeneratorStatementExtensions.cs#L1-L31","documentation":"EmitCallBaseParameterlessCtor (internal) requires the ConstructorBuilder to have a non-null DeclaringType so it can resolve the base type's parameterless constructor. It throws ArgumentException otherwise-an internal precondition guarding constructor resolution.","triggerScenarios":"The emitter receives a ConstructorBuilder whose DeclaringType is null, so it cannot walk to BaseType to find a parameterless ctor.","commonSituations":"Library codegen bug while building a generated benchmark type; not user-reachable via normal configuration.","solutions":["Simplify the benchmark type structure and retry.","Upgrade BenchmarkDotNet; file an issue with a minimal repro if it persists."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { runner.Run(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"non-null DeclaringType\")) { /* simplify type layout, report issue */ }","preventionTips":["Use standard benchmark class structures.","Upgrade BenchmarkDotNet for constructor-emit fixes.","File reproducible issues."],"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"}