microsoft/semantic-kernel · critical · InvalidProgramException

Dapr Test Host did not start

Error message

Dapr Test Host did not start

What it means

Thrown by the Dapr `ProcessTestFixture` after a bounded health-check loop against the Dapr test host never observed an HTTP 200 health response. The fixture polls the health endpoint (with try/catch swallowing `HttpRequestException`) and, if no OK is seen within the loop bounds, abandons startup. It is an InvalidProgramException.

Source

Thrown at dotnet/src/Experimental/Process.IntegrationTestRunner.Dapr/ProcessTestFixture.cs:115

                break;
            }

            try
            {
                var healthResponse = await this._httpClient!.GetAsync(new Uri("http://localhost:5200/daprHealth"));
                if (healthResponse.StatusCode == HttpStatusCode.OK)
                {
                    await Task.Delay(TimeSpan.FromSeconds(10));
                    return;
                }
            }
            catch (HttpRequestException)
            {
                // Do nothing, just wait
            }
        }

        throw new InvalidProgramException("Dapr Test Host did not start");
    }

    /// <summary>
    /// Starts a process.
    /// </summary>
    /// <param name="process">The process to start.</param>
    /// <param name="kernel">An instance of <see cref="Kernel"/></param>
    /// <param name="initialEvent">An optional initial event.</param>
    /// <param name="externalMessageChannel">channel used for external messages</param>
    /// <returns>A <see cref="Task{KernelProcessContext}"/></returns>
    public async Task<KernelProcessContext> StartProcessAsync(KernelProcess process, Kernel kernel, KernelProcessEvent initialEvent, IExternalKernelProcessMessageChannel? externalMessageChannel = null)
    {
        // Actual Kernel injection of Kernel and ExternalKernelProcessMessageChannel is in dotnet\src\Experimental\Process.IntegrationTestHost.Dapr\Program.cs
        var context = new DaprTestProcessContext(process, this._httpClient!);
        await context.StartWithEventAsync(initialEvent);
        return context;
    }

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Manually start the Dapr test host and `curl` the health endpoint to confirm it returns 200.
  2. Check the host process logs for startup exceptions (binding, missing Dapr sidecar, config).
  3. Ensure the expected port is free and the Dapr runtime (daprd) is running.
  4. If the host is slow, increase the health-check retry budget in the fixture.

Example fix

// before (host never reachable)
// run tests directly after building
// after (verify host + health manually first)
// 1) dotnet run --project Process.IntegrationTestRunner.Dapr.Host
// 2) curl http://localhost:<port>/health  -> expect 200
// 3) then run the test suite
Defensive patterns

Strategy: validation

Validate before calling

using var probe = new HttpClient();
var ok = false;
for (int i = 0; i < 30; i++)
{
    try
    {
        using var r = await probe.GetAsync("http://localhost:5200/health");
        if (r.IsSuccessStatusCode) { ok = true; break; }
    }
    catch (HttpRequestException) { }
    await Task.Delay(1000);
}
if (!ok) throw new InvalidOperationException("Dapr host health check failed; aborting tests.");

Type guard

bool IsPortListening(int port) =>
    System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties()
        .GetActiveTcpListeners().Any(a => a.Port == port);

Try / catch

try { await fixture.InitializeAsync(); }
catch (InvalidProgramException ex) when (ex.Message.Contains("Dapr Test Host did not start"))
{ _logger.LogCritical(ex, "Dapr host unreachable; verify runtime/port."); throw; }

Prevention

When it happens

Trigger: The Dapr test host process failed to launch, crashed during startup, or is unreachable (port not listening, firewall); the health endpoint path/port is wrong; the host is too slow and exceeds the retry budget.

Common situations: Dapr CLI/runtime not installed or wrong version; the test host port is already in use; CI environment lacks network/binding permissions; the host startup throws before binding the health route.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/f92a973635120ac7. Report an issue: GitHub.