dotnet/BenchmarkDotNet · error · InvalidOperationException

Unable to get value of 'ConsoleRunnerPackage'.

Error message

Unable to get value of 'ConsoleRunnerPackage'.

What it means

GetRunnerPath found the 'ConsoleRunnerPackage' field on DotTrace but its value is null. The field exists; DotTrace.InitAsync has not populated the package instance (or populated then nulled it).

Source

Thrown at src/BenchmarkDotNet.Diagnostics.dotTrace/DotTraceDiagnoser.cs:59

    protected override void Detach()
    {
        DotTrace.Detach();
    }

    protected override string CreateSnapshotFilePath(DiagnoserActionParameters parameters)
    {
        return ArtifactFileNameHelper.GetFilePath(parameters, "snapshots", DateTime.Now, "dtp", ".0000".Length);
    }

    protected override string GetRunnerPath()
    {
        var consoleRunnerPackageField = typeof(DotTrace).GetField("ConsoleRunnerPackage", BindingFlags.NonPublic | BindingFlags.Static);
        if (consoleRunnerPackageField == null)
            throw new InvalidOperationException("Field 'ConsoleRunnerPackage' not found.");

        object? consoleRunnerPackage = consoleRunnerPackageField.GetValue(null);
        if (consoleRunnerPackage == null)
            throw new InvalidOperationException("Unable to get value of 'ConsoleRunnerPackage'.");

        var consoleRunnerPackageType = consoleRunnerPackage.GetType();
        var getRunnerPathMethod = consoleRunnerPackageType.GetMethod("GetRunnerPath");
        if (getRunnerPathMethod == null)
            throw new InvalidOperationException("Method 'GetRunnerPath' not found.");

        string? runnerPath = getRunnerPathMethod.Invoke(consoleRunnerPackage, null) as string;
        if (runnerPath == null)
            throw new InvalidOperationException("Unable to invoke 'GetRunnerPath'.");

        return runnerPath;
    }

    internal override bool IsSupported(RuntimeMoniker runtimeMoniker)
    {
        switch (runtimeMoniker)
        {
            case RuntimeMoniker.HostProcess:

View on GitHub (pinned to b515068b61)

Solutions

  1. Let InitTool run to completion before GetRunnerPath (SnapshotProfilerBase.Init already does this).
  2. Clear the dotTrace prerequisite cache and re-run InitAsync.
  3. Match the SelfApi version to your BDN build.
Defensive patterns

Strategy: fallback

Try / catch

try { /* use dotTrace diagnoser */ }
catch (InvalidOperationException ex) when (ex.Message.Contains("Unable to get value of 'ConsoleRunnerPackage'"))
{
    log.Error("dotTrace prerequisite not initialized; clear cache and let InitAsync re-download.");
}

Prevention

When it happens

Trigger: InitTool (DotTrace.InitAsync) returned without throwing but never assigned the static package instance, or assigned and reset it. Same shape as the dotMemory null-field case.

Common situations: InitAsync completed against a corrupted/partial prerequisite; GetRunnerPath invoked out of order with Init; SelfApi build that lazily instantiates the package.

Related errors


AI-assisted analysis of dotnet/BenchmarkDotNet@b515068b61 (2026-08-13). Data as JSON: /api/errors/04d5210b7712521e. Report an issue: GitHub.