microsoft/semantic-kernel · error · ConfigurationNotFoundException

Configuration section '{section}' not found

Error message

Configuration section '{section}' not found

What it means

Thrown by the Step04_AgentOrchestration constructor when UseOpenAIConfig is true but this.ApiKey is null. Identical pattern to Step10: the single-arg ConfigurationNotFoundException reports 'OpenAI:ApiKey' as a missing configuration section.

Source

Thrown at dotnet/samples/GettingStartedWithProcesses/Step04/Step04_AgentOrchestration.cs:31

using Microsoft.SemanticKernel.Connectors.OpenAI;
using OpenAI;
using SharedSteps;
using Step04.Plugins;
using Step04.Steps;

namespace Step04;

/// <summary>
/// Demonstrate creation of a <see cref="KernelProcess"/> that orchestrates an <see cref="Agent"/> conversation.
/// For visual reference of the process check <see href="https://github.com/microsoft/semantic-kernel/tree/main/dotnet/samples/GettingStartedWithProcesses/README.md#step04_agentorchestration" >diagram</see>.
/// </summary>
public class Step04_AgentOrchestration : BaseTest
{
    public Step04_AgentOrchestration(ITestOutputHelper output) : base(output, redirectSystemConsoleOutput: true)
    {
        this.Client =
    this.UseOpenAIConfig ?
        OpenAIAssistantAgent.CreateOpenAIClient(new ApiKeyCredential(this.ApiKey ?? throw new ConfigurationNotFoundException("OpenAI:ApiKey"))) :
        !string.IsNullOrWhiteSpace(this.ApiKey) ?
            OpenAIAssistantAgent.CreateAzureOpenAIClient(new ApiKeyCredential(this.ApiKey), new Uri(this.Endpoint!)) :
            OpenAIAssistantAgent.CreateAzureOpenAIClient(new AzureCliCredential(), new Uri(this.Endpoint!));
    }

    protected OpenAIClient Client { get; init; }

    // Target Open AI Services
    protected override bool ForceOpenAI => true;

    /// <summary>
    /// Orchestrates a single agent gathering user input and then delegating to a group of agents.
    /// The group of agents provide a response back to the single agent who continues to
    /// interact with the user.
    /// </summary>
    [Fact]
    public async Task DelegatedGroupChatAsync()
    {

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Configure 'OpenAI:ApiKey' via user-secrets or appsettings for the Step04 sample project.
  2. Confirm ForceOpenAI/UseOpenAIConfig is the intended path; otherwise set Azure OpenAI ApiKey + Endpoint.
  3. Ensure TestConfiguration loads the configuration provider so ApiKey is populated before construction.

Example fix

// before
OpenAIAssistantAgent.CreateOpenAIClient(new ApiKeyCredential(this.ApiKey ?? throw new ConfigurationNotFoundException("OpenAI:ApiKey")))
// after
if (string.IsNullOrWhiteSpace(this.ApiKey))
    throw new ConfigurationNotFoundException("OpenAI", "ApiKey");
OpenAIAssistantAgent.CreateOpenAIClient(new ApiKeyCredential(this.ApiKey!));
Defensive patterns

Strategy: validation

Validate before calling

string apiKey = config["OpenAI:ApiKey"];
if (string.IsNullOrWhiteSpace(apiKey))
    throw new ConfigurationNotFoundException("OpenAI", "ApiKey");

Try / catch

try { Client = ...CreateOpenAIClient(new ApiKeyCredential(apiKey)); }
catch (ConfigurationNotFoundException) { /* prompt user to set OpenAI:ApiKey */ }

Prevention

When it happens

Trigger: Constructing Step04_AgentOrchestration with UseOpenAIConfig == true (note ForceOpenAI override is true) and ApiKey unset in configuration.

Common situations: Running the Step04 process sample without configured OpenAI:ApiKey user-secrets; CI missing secrets; cloned repo run naively.

Related errors


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