microsoft/autogen · error · ArgumentException
Kernel is not running
Error message
Kernel is not running
What it means
Thrown by InteractiveService.SubmitCommandAsync when the internal kernel field is null — the interactive kernel process has not been started (or the service was never given one). All Submit*CodeAsync helpers route through this guard, so any code submission before startup fails with ArgumentException('Kernel is not running').
Source
Thrown at dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs:62
public Kernel? Kernel => this.kernel;
public async Task<bool> StartAsync(string workingDirectory, CancellationToken ct = default)
{
if (this.kernel != null)
{
return true;
}
this.kernel = await this.CreateKernelAsync(workingDirectory, true, ct);
return true;
}
public async Task<string?> SubmitCommandAsync(SubmitCode cmd, CancellationToken ct)
{
if (this.kernel == null)
{
throw new ArgumentException("Kernel is not running");
}
return await this.kernel.RunSubmitCodeCommandAsync(cmd.Code, cmd.TargetKernelName, ct);
}
public async Task<string?> SubmitPowershellCodeAsync(string code, CancellationToken ct)
{
var command = new SubmitCode(code, targetKernelName: "pwsh");
return await this.SubmitCommandAsync(command, ct);
}
public async Task<string?> SubmitCSharpCodeAsync(string code, CancellationToken ct)
{
var command = new SubmitCode(code, targetKernelName: "csharp");
return await this.SubmitCommandAsync(command, ct);
}
public bool RestoreDotnetInteractive()View on GitHub (pinned to 027ecf0a37)
Solutions
- Await service.StartAsync(workingDirectory) once before any submit call
- Check service.Kernel is not null before submitting (it is exposed as a public property) as a cheap pre-condition
- If the kernel died, recreate the InteractiveService and StartAsync again rather than reusing it
- Avoid calling submit after DisposeAsync/Dispose
Example fix
// before:
var service = new InteractiveService(dir);
await service.SubmitCSharpCodeAsync("1+1", ct); // throws: kernel null
// after:
var service = new InteractiveService(dir);
await service.StartAsync(workingDirectory);
await service.SubmitCSharpCodeAsync("1+1", ct); Defensive patterns
Strategy: validation
Validate before calling
// Guard before submitting
if (service.Kernel is null)
{
var ok = await service.StartAsync(workingDirectory, ct);
if (!ok) throw new InvalidOperationException("Failed to start interactive kernel");
}
var result = await service.SubmitCSharpCodeAsync(code, ct); Type guard
static bool IsKernelRunning(InteractiveService s) => s.Kernel is not null;
Try / catch
try { await service.SubmitCSharpCodeAsync(code, ct); }
catch (ArgumentException e) when (e.Message == "Kernel is not running")
{ /* kernel not started or died: recreate service, await StartAsync, retry once */ } Prevention
- Await StartAsync exactly once at startup before any submit
- Check the public Kernel property as a cheap pre-condition
When it happens
Trigger: Creating InteractiveService with the directory constructor (kernel starts as null) and calling SubmitCSharpCodeAsync/SubmitPowershellCodeAsync/SubmitCommandAsync before awaiting StartAsync, or after a kernel crash/dispose left kernel null.
Common situations: Forgetting the awaited StartAsync call, calling submit from a thread that races ahead of startup, using the service after Dispose, or the kernel process dying mid-session (then a subsequent submit throws).
Related errors
- InteractiveService is not initialized.
- Installing directory is not set
- Failed to restore dotnet interactive tool.
- The group chat has not been initialized. It must be run befo
- Error initializing: {this.GetType().FullName}; already initi
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/c461d76c81275470.
Report an issue: GitHub.