github/copilot-sdk · error · InvalidOperationException

Elicitation is not supported by the host. Check…

Error message

Elicitation is not supported by the host. Check session.Capabilities.Ui?.Elicitation before calling UI methods.

What it means

AssertElicitation is a precondition check: it throws InvalidOperationException when the host did not advertise UI elicitation capability (Capabilities.Ui?.Elicitation != true) but an elicitation API (showing input dialogs to the user) was called. The message points you to verify the capability flag first.

Solutions

  1. Check session.Capabilities.Ui?.Elicitation == true before calling any elicitation API.
  2. Fall back to a non-UI flow (CLI prompts, defaults, or config values) when elicitation is unsupported.
  3. Upgrade the host/CLI to a version that supports elicitation.
  4. If you control the host, declare the ui.elicitation capability in its initialize response.

Example fix

// before
var answer = await session.Ui.RequestInputAsync(new() { Message = "Name?" });

// after
if (session.Capabilities.Ui?.Elicitation == true)
    var answer = await session.Ui.RequestInputAsync(new() { Message = "Name?" });
else
    var answer = PromptFallback("Name?");
Defensive patterns

Strategy: type-guard

Validate before calling

if (session.Capabilities.Ui?.Elicitation != true)
    return await FallbackPromptAsync(message);

Type guard

static bool SupportsElicitation(Session s) => s.Capabilities?.Ui?.Elicitation == true;

Try / catch

try { return await session.Ui.RequestInputAsync(req); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Elicitation is not supported"))
{ return await FallbackPromptAsync(req.Message); }

Prevention

When it happens

Trigger: Calling session UI elicitation methods (e.g. RequestInput/ShowForm style APIs) against a host — CLI, CI runner, IDE — whose capabilities response lacks ui.elicitation or sets it false.

Common situations: Running a Copilot SDK app inside headless/CI environments; older CLI versions without elicitation support; embedding the session in a custom host that never declares the Ui capability.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/729896822ce0262b. Report an issue: GitHub.

Appendix: source

Thrown at dotnet/src/Session.cs:1532

                {
                    Action = UIElicitationResponseAction.Cancel
                });
            }
            catch (Exception innerEx) when (innerEx is IOException or ObjectDisposedException)
            {
                // Connection lost — nothing we can do
            }
        }
    }

    /// <summary>
    /// Throws if the host does not support elicitation.
    /// </summary>
    private void AssertElicitation()
    {
        if (Capabilities.Ui?.Elicitation != true)
        {
            throw new InvalidOperationException(
                "Elicitation is not supported by the host. " +
                "Check session.Capabilities.Ui?.Elicitation before calling UI methods.");
        }
    }

    /// <summary>
    /// Implements <see cref="ISessionUiApi"/> backed by the session's RPC connection.
    /// </summary>
    private sealed class SessionUiApiImpl(CopilotSession session) : ISessionUiApi
    {
        // Parses a JSON string and returns a detached JsonElement. Using `using`
        // ensures the pooled buffers backing the JsonDocument are released
        // promptly; the cloned RootElement is independent of the document.
        private static JsonElement ParseJsonElement(string json)
        {
            using var doc = JsonDocument.Parse(json);
            return doc.RootElement.Clone();
        }

View on GitHub (pinned to cd8cf15dc3)