{"record":{"id":"e9d244ab7f00edfc","repo":"microsoft/semantic-kernel","slug":"configuration-section-section-not-found","errorCode":null,"errorMessage":"Configuration section '{section}' not found","messagePattern":"Configuration section '(.+?)' not found","errorType":"exception","errorClass":"ConfigurationNotFoundException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/GettingStartedWithAgents/Step10_MultiAgent_Declarative.cs","lineNumber":95,"sourceCode":"        }\n        finally\n        {\n            var azureaiAgent = agent as AzureAIAgent;\n            Assert.NotNull(azureaiAgent);\n            await azureaiAgent.Client.Administration.DeleteAgentAsync(azureaiAgent.Id);\n\n            if (agentThread is not null)\n            {\n                await agentThread.DeleteAsync();\n            }\n        }\n    }\n\n    public Step10_MultiAgent_Declarative(ITestOutputHelper output) : base(output)\n    {\n        var openaiClient =\n           this.UseOpenAIConfig ?\n               OpenAIAssistantAgent.CreateOpenAIClient(new ApiKeyCredential(this.ApiKey ?? throw new ConfigurationNotFoundException(\"OpenAI:ApiKey\"))) :\n               !string.IsNullOrWhiteSpace(this.ApiKey) ?\n                   OpenAIAssistantAgent.CreateAzureOpenAIClient(new ApiKeyCredential(this.ApiKey), new Uri(this.Endpoint!)) :\n                   OpenAIAssistantAgent.CreateAzureOpenAIClient(new AzureCliCredential(), new Uri(this.Endpoint!));\n\n        var agentsClient = AzureAIAgent.CreateAgentsClient(TestConfiguration.AzureAI.Endpoint, new AzureCliCredential());\n\n        var builder = Kernel.CreateBuilder();\n        builder.Services.AddSingleton<OpenAIClient>(openaiClient);\n        builder.Services.AddSingleton<PersistentAgentsClient>(agentsClient);\n        AddChatCompletionToKernel(builder);\n        this._kernel = builder.Build();\n\n        this._kernelAgentFactory =\n            new AggregatorAgentFactory(\n                new ChatCompletionAgentFactory(),\n                new OpenAIAssistantAgentFactory(),\n                new AzureAIAgentFactory());\n    }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/GettingStartedWithAgents/Step10_MultiAgent_Declarative.cs#L77-L113","documentation":"Thrown by the sample's constructor when the OpenAI/Azure OpenAI API key resolves to null while UseOpenAIConfig is true. It uses the single-argument ConfigurationNotFoundException constructor, so the entire 'OpenAI:ApiKey' string is reported as a configuration section, signaling that required test configuration is missing.","triggerScenarios":"Constructing Step10_MultiAgent_Declarative with UseOpenAIConfig == true and this.ApiKey null/whitespace; i.e. the test/appsettings configuration did not supply an OpenAI API key.","commonSituations":"Running the GettingStarted samples locally without setting user-secrets or appsettings 'OpenAI:ApiKey'; CI without configured secrets; cloning the repo and expecting samples to run without configuration.","solutions":["Set the OpenAI API key via .NET user-secrets: 'dotnet user-secrets set \"OpenAI:ApiKey\" <key>' in the sample project, or add it to appsettings.json / TestConfiguration.","If targeting Azure OpenAI, ensure UseOpenAIConfig is false and ApiKey (or Azure CLI credential) + Endpoint are configured.","Verify the configuration provider is loaded in BaseTest so TestConfiguration populates this.ApiKey before the constructor runs."],"exampleFix":"// before\nOpenAIAssistantAgent.CreateOpenAIClient(new ApiKeyCredential(this.ApiKey ?? throw new ConfigurationNotFoundException(\"OpenAI:ApiKey\")))\n// after - guard explicitly and give an actionable message\nif (string.IsNullOrWhiteSpace(this.ApiKey))\n    throw new ConfigurationNotFoundException(\"OpenAI\", \"ApiKey\");\nOpenAIAssistantAgent.CreateOpenAIClient(new ApiKeyCredential(this.ApiKey!));","handlingStrategy":"validation","validationCode":"string apiKey = config[\"OpenAI:ApiKey\"];\nif (string.IsNullOrWhiteSpace(apiKey))\n    throw new ConfigurationNotFoundException(\"OpenAI\", \"ApiKey\");\n// proceed to construct the sample","typeGuard":null,"tryCatchPattern":"try { var sample = new Step10_MultiAgent_Declarative(output); }\ncatch (ConfigurationNotFoundException ex) when (ex.Section == \"OpenAI:ApiKey\")\n    { Console.Error.WriteLine(\"Set 'OpenAI:ApiKey' via user-secrets.\"); }","preventionTips":["Run 'dotnet user-secrets init' then 'dotnet user-secrets set \"OpenAI:ApiKey\" <key>' in each sample project.","Fail fast on missing configuration in startup, before constructing clients.","Keep a checklist of required keys per sample in the repo README."],"tags":["configuration","openai","secrets","samples","azure"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}