microsoft/autogen · error · ArgumentException
InteractiveService is not initialized.
Error message
InteractiveService is not initialized.
What it means
Thrown by DotnetInteractiveFunction.RunCode when its internal _interactiveService field is null. The function was constructed without an InteractiveService, so there is no kernel to submit the C# code to, and it throws ArgumentException('InteractiveService is not initialized.').
Source
Thrown at dotnet/src/AutoGen.DotnetInteractive/DotnetInteractiveFunction.cs:77
var document = new InteractiveDocument();
using var stream = File.OpenWrite(_notebookPath);
Notebook.Write(document, stream, this._kernelInfoCollection);
stream.Flush();
stream.Dispose();
}
}
/// <summary>
/// Run existing dotnet code from message. Don't modify the code, run it as is.
/// </summary>
/// <param name="code">code.</param>
[Function]
public async Task<string> RunCode(string code)
{
if (this._interactiveService == null)
{
throw new ArgumentException("InteractiveService is not initialized.");
}
var result = await this._interactiveService.SubmitCSharpCodeAsync(code, default);
if (result != null)
{
// if result contains Error, return entire message
if (result.StartsWith("Error:"))
{
return result;
}
// add cell if _notebookPath is not null
if (this._notebookPath != null)
{
await AddCellAsync(code, "csharp");
}
// if result is over 100 characters, only return the first 100 characters.View on GitHub (pinned to 027ecf0a37)
Solutions
- Construct DotnetInteractiveFunction with a live InteractiveService (or however the public API requires it) before registering it as a tool
- Call and await service.StartAsync(workingDirectory) first so the kernel is actually running
- Verify the service is non-null and started in a startup check before the agent loop begins
Example fix
// before: var func = new DotnetInteractiveFunction(); // no service // after: var service = new InteractiveService(installDir); await service.StartAsync(workDir); var func = new DotnetInteractiveFunction(service);
Defensive patterns
Strategy: validation
Validate before calling
// Verify the function is backed by a running service before the agent loop starts
if (dotnetInteractiveFunction is null || !IsServiceAttached(dotnetInteractiveFunction))
throw new InvalidOperationException("DotnetInteractiveFunction lacks an InteractiveService");
// simplest robust check: construct it yourself from a started service Try / catch
try { var result = await func.RunCode(code); }
catch (ArgumentException e) when (e.Message == "InteractiveService is not initialized.")
{ /* construct function with a started InteractiveService and retry */ } Prevention
- Always build DotnetInteractiveFunction from a started InteractiveService
- Assert Kernel != null at startup
When it happens
Trigger: Creating DotnetInteractiveFunction via a constructor/path that leaves _interactiveService null, then invoking the RunCode tool (directly or through an LLM function call).
Common situations: Partially initializing the function object (e.g. for testing), dependency-injection misconfiguration, or constructing the function before the interactive session is available and forgetting to attach it.
Related errors
- Kernel is not running
- Failed to restore dotnet interactive tool.
- Installing directory is not set
- No coder message found
- Please set OPENAI_API_KEY environment variable.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/45cd3df64bee0956.
Report an issue: GitHub.