{"record":{"id":"eb1a7ab12c85fa53","repo":"microsoft/semantic-kernel","slug":"configuration-is-not-setup-correctly","errorCode":null,"errorMessage":"Configuration is not setup correctly.","messagePattern":"Configuration is not setup correctly\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"dotnet/samples/Demos/BookingRestaurant/Program.cs","lineNumber":22,"sourceCode":"using Azure.Identity;\nusing Microsoft.Extensions.Configuration;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Logging;\nusing Microsoft.Graph;\nusing Microsoft.SemanticKernel;\nusing Microsoft.SemanticKernel.ChatCompletion;\nusing Microsoft.SemanticKernel.Connectors.OpenAI;\nusing Plugins;\n\n// Use this for application permissions\nstring[] scopes;\n\nvar config = new ConfigurationBuilder()\n    .AddUserSecrets<Program>()\n    .AddEnvironmentVariables()\n    .Build()\n    .Get<AppConfig>() ??\n    throw new InvalidOperationException(\"Configuration is not setup correctly.\");\n\nconfig.Validate();\n\nTokenCredential credential = null!;\nif (config.AzureEntraId!.InteractiveBrowserAuthentication) // Authentication As User\n{\n    /// Use this if using user delegated permissions\n    scopes = [\"User.Read\", \"BookingsAppointment.ReadWrite.All\"];\n\n    credential = new InteractiveBrowserCredential(\n        new InteractiveBrowserCredentialOptions\n        {\n            TenantId = config.AzureEntraId.TenantId,\n            ClientId = config.AzureEntraId.ClientId,\n            AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,\n            RedirectUri = new Uri(config.AzureEntraId.InteractiveBrowserRedirectUri!)\n        });\n}","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/BookingRestaurant/Program.cs#L4-L40","documentation":"The Booking Restaurant sample builds an AppConfig from user secrets plus environment variables and uses a null-coalescing throw when Get<AppConfig>() returns null. This means no configuration source could bind the required shape at all. The exception fires before Validate() runs, so it is a 'config entirely missing' failure rather than a field-level one.","triggerScenarios":"No user secrets are registered for the project (missing `dotnet user-secrets` init/set) AND no matching environment variables are present, so ConfigurationBuilder.Get<AppConfig>() returns null.","commonSituations":"First run of the sample on a machine without secrets, cloning the repo without running the README setup, wrong secrets GUID (user secrets bound to a different assembly), or renamed config keys that no longer bind.","solutions":["Run `dotnet user-secrets init` then `dotnet user-secrets set <Key> <Value>` for each AppConfig property per the README.","Alternatively export the equivalent environment variables (hierarchical keys use __ as separator).","Verify the user-secrets ID in the .csproj matches the assembly so secrets resolve, then re-run.","Confirm AppConfig.Validate() passes once Get() is non-null; this throw only covers the null case."],"exampleFix":"// before\n.Get<AppConfig>() ??\n    throw new InvalidOperationException(\"Configuration is not setup correctly.\");\n\n// after (diagnostic: keep throw, but surface what is missing)\nvar raw = new ConfigurationBuilder()\n    .AddUserSecrets<Program>()\n    .AddEnvironmentVariables()\n    .Build();\nvar config = raw.Get<AppConfig>() ??\n    throw new InvalidOperationException(\n        \"Configuration is not setup correctly. Missing keys: \" +\n        string.Join(\", \", typeof(AppConfig).GetProperties().Select(p => p.Name)));","handlingStrategy":"validation","validationCode":"var raw = new ConfigurationBuilder().AddUserSecrets<Program>().AddEnvironmentVariables().Build();\nvar missing = typeof(AppConfig).GetProperties()\n    .Where(p => raw[typeof(AppConfig).Name + \":\" + p.Name] is null)\n    .Select(p => p.Name).ToList();\nif (missing.Any())\n    throw new InvalidOperationException(\"Missing config keys: \" + string.Join(\", \", missing));","typeGuard":"static bool IsConfigPresent(IConfigurationRoot root) => root.Get<AppConfig>() is not null;","tryCatchPattern":"try { config.Validate(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Configuration is not setup\"))\n{\n    Console.Error.WriteLine(\"Run: dotnet user-secrets set <Key> <Value> for each AppConfig property.\");\n    return;\n}","preventionTips":["Run `dotnet user-secrets init` and set every AppConfig property before first run.","Document required keys in the README and validate them explicitly with named messages.","Use environment variables as a CI-friendly fallback (hierarchical __ separator)."],"tags":["configuration","user-secrets","environment-variables","samples"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}