dotnet/BenchmarkDotNet · error · ArgumentException
The constructorBuilder should have non-null DeclaringType.
Error message
The constructorBuilder should have non-null DeclaringType.
What it means
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.
Source
Thrown at src/BenchmarkDotNet/Helpers/Reflection.Emit/IlGeneratorStatementExtensions.cs:13
using System.Reflection;
using System.Reflection.Emit;
namespace BenchmarkDotNet.Helpers.Reflection.Emit
{
internal static class IlGeneratorStatementExtensions
{
public static void EmitCallBaseParameterlessCtor(this ILGenerator ilGenerator, ConstructorBuilder constructorBuilder)
{
if (constructorBuilder.IsStatic)
throw new ArgumentException($"Can not emit base call for {constructorBuilder}");
if (constructorBuilder.DeclaringType == null)
throw new ArgumentException($"The {nameof(constructorBuilder)} should have non-null {nameof(constructorBuilder.DeclaringType)}.");
/*
IL_0000: ldarg.0
IL_0001: call instance void [BenchmarkDotNet]BenchmarkDotNet.Samples.SampleBenchmark::.ctor()
*/
var baseCtor = constructorBuilder.DeclaringType.BaseType?.GetConstructor([]);
if (baseCtor == null)
throw new ArgumentException(
$"Base type of {constructorBuilder.DeclaringType} has no public parameterless constructor.");
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Call, baseCtor);
}
public static void EmitCtorReturn(this ILGenerator ilBuilder, ConstructorBuilder methodBuilder)
{
// IL_0000: ret
ilBuilder.Emit(OpCodes.Ret);View on GitHub (pinned to b515068b61)
Solutions
- Simplify the benchmark type structure and retry.
- Upgrade BenchmarkDotNet; file an issue with a minimal repro if it persists.
Defensive patterns
Strategy: try-catch
Try / catch
try { runner.Run(); }
catch (ArgumentException ex) when (ex.Message.Contains("non-null DeclaringType")) { /* simplify type layout, report issue */ } Prevention
- Use standard benchmark class structures.
- Upgrade BenchmarkDotNet for constructor-emit fixes.
- File reproducible issues.
When it happens
Trigger: The emitter receives a ConstructorBuilder whose DeclaringType is null, so it cannot walk to BaseType to find a parameterless ctor.
Common situations: Library codegen bug while building a generated benchmark type; not user-reachable via normal configuration.
Related errors
- Method {methodToCall} should be static method.
- The methodToCall should have non-null DeclaringType.
- Method {methodToCall} should be instance method.
- The optionalLocalThis should be null for static calls
- Can not emit base call for {constructorBuilder}
AI-assisted analysis of dotnet/BenchmarkDotNet@b515068b61 (2026-08-13).
Data as JSON: /api/errors/9acc10107fd3bd62.
Report an issue: GitHub.