{"record":{"id":"11f93389b5d5519f","repo":"microsoft/semantic-kernel","slug":"configuration-is-not-provided","errorCode":null,"errorMessage":"Configuration is not provided.","messagePattern":"Configuration is not provided\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"dotnet/samples/Demos/TimePlugin/Program.cs","lineNumber":16,"sourceCode":"﻿// Copyright (c) Microsoft. All rights reserved.\n#pragma warning disable VSTHRD111 // Use ConfigureAwait(bool)\n#pragma warning disable CA1050 // Declare types in namespaces\n#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task\n\nusing System.ComponentModel;\nusing Microsoft.Extensions.Configuration;\nusing Microsoft.SemanticKernel;\nusing Microsoft.SemanticKernel.ChatCompletion;\nusing Microsoft.SemanticKernel.Connectors.OpenAI;\n\nvar config = new ConfigurationBuilder()\n    .AddUserSecrets<Program>()\n    .AddEnvironmentVariables()\n    .Build()\n    ?? throw new InvalidOperationException(\"Configuration is not provided.\");\n\nArgumentNullException.ThrowIfNull(config[\"OpenAI:ChatModelId\"], \"OpenAI:ChatModelId\");\nArgumentNullException.ThrowIfNull(config[\"OpenAI:ApiKey\"], \"OpenAI:ApiKey\");\n\nvar kernelBuilder = Kernel.CreateBuilder().AddOpenAIChatCompletion(\n    modelId: config[\"OpenAI:ChatModelId\"]!,\n    apiKey: config[\"OpenAI:ApiKey\"]!);\n\nkernelBuilder.Plugins.AddFromType<TimeInformationPlugin>();\nvar kernel = kernelBuilder.Build();\n\n// Get chat completion service\nvar chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();\n\n// Enable auto function calling\nOpenAIPromptExecutionSettings openAIPromptExecutionSettings = new()\n{\n    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/TimePlugin/Program.cs#L1-L34","documentation":"The null-coalescing throw checks whether ConfigurationBuilder().Build() returns null, then throws InvalidOperationException. In practice, Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() never returns null — it always returns a non-null IConfigurationRoot — making this throw effectively unreachable dead code. The check is defensive but cannot fire under normal library behavior.","triggerScenarios":"This throw is unreachable in practice: Build() returns a non-null IConfigurationRoot even when no providers are configured. It would only fire if a custom IConfigurationBuilder implementation overrode Build() to return null, which is not the case here.","commonSituations":"Developers see this message and believe configuration is missing, but the real problem is that config keys (OpenAI:ChatModelId, OpenAI:ApiKey) are null — the subsequent ArgumentNullException.ThrowIfNull calls are what actually fire for missing keys, not this line.","solutions":["Recognize this line is effectively dead code; the real validation happens on the next two lines via ArgumentNullException.ThrowIfNull.","Ensure OpenAI:ChatModelId and OpenAI:ApiKey are set in user secrets or environment variables.","Remove the misleading null-coalescing throw or replace it with a meaningful check on specific keys.","If you encounter this exact message in a stack trace, suspect a custom IConfigurationBuilder or a framework version anomaly — otherwise look at the ArgumentNullException lines below it."],"exampleFix":"// before — unreachable check on Build()\nvar config = new ConfigurationBuilder()\n    .AddUserSecrets<Program>()\n    .AddEnvironmentVariables()\n    .Build()\n    ?? throw new InvalidOperationException(\"Configuration is not provided.\");\n\n// after — Build() never returns null; validate the keys that matter\nvar config = new ConfigurationBuilder()\n    .AddUserSecrets<Program>()\n    .AddEnvironmentVariables()\n    .Build();\n\nArgumentNullException.ThrowIfNull(config[\"OpenAI:ChatModelId\"], \"OpenAI:ChatModelId\");\nArgumentNullException.ThrowIfNull(config[\"OpenAI:ApiKey\"], \"OpenAI:ApiKey\");","handlingStrategy":"validation","validationCode":"// Skip the dead Build() null-check; validate the keys that matter\nvar modelId = config[\"OpenAI:ChatModelId\"];\nvar apiKey = config[\"OpenAI:ApiKey\"];\nif (string.IsNullOrWhiteSpace(modelId)) throw new ArgumentNullException(nameof(modelId), \"Set OpenAI:ChatModelId in user secrets or env.\");\nif (string.IsNullOrWhiteSpace(apiKey)) throw new ArgumentNullException(nameof(apiKey), \"Set OpenAI:ApiKey in user secrets or env.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't rely on Build() returning null — it never does in Microsoft.Extensions.Configuration.","Validate specific required keys immediately after Build().","Use user secrets consistently and verify the UserSecretsId in the .csproj."],"tags":["configuration","dead-code","defensive","secrets","time-plugin"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}