{"record":{"id":"e8d7becc7cad87cf","repo":"microsoft/semantic-kernel","slug":"ai-chat-service-type-appconfig-ragconfig-aichats","errorCode":null,"errorMessage":"AI Chat Service type '{appConfig.RagConfig.AIChatService}' is not supported.","messagePattern":"AI Chat Service type '(.+?)' is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"critical","filePath":"dotnet/samples/Demos/VectorStoreRAG/Program.cs","lineNumber":48,"sourceCode":"// and add Chat Completion and Text Embedding Generation services.\nvar kernelBuilder = builder.Services.AddKernel();\n\nswitch (appConfig.RagConfig.AIChatService)\n{\n    case \"AzureOpenAI\":\n        kernelBuilder.AddAzureOpenAIChatCompletion(\n            appConfig.AzureOpenAIConfig.ChatDeploymentName,\n            appConfig.AzureOpenAIConfig.Endpoint,\n            new AzureCliCredential());\n        break;\n    case \"OpenAI\":\n        kernelBuilder.AddOpenAIChatCompletion(\n            appConfig.OpenAIConfig.ModelId,\n            appConfig.OpenAIConfig.ApiKey,\n            appConfig.OpenAIConfig.OrgId);\n        break;\n    default:\n        throw new NotSupportedException($\"AI Chat Service type '{appConfig.RagConfig.AIChatService}' is not supported.\");\n}\n\nswitch (appConfig.RagConfig.AIEmbeddingService)\n{\n    case \"AzureOpenAIEmbeddings\":\n        builder.Services.AddSingleton<IEmbeddingGenerator>(\n            sp => new AzureOpenAIClient(new Uri(appConfig.AzureOpenAIEmbeddingsConfig.Endpoint), new AzureCliCredential())\n                .GetEmbeddingClient(appConfig.AzureOpenAIEmbeddingsConfig.DeploymentName)\n                .AsIEmbeddingGenerator());\n        break;\n    case \"OpenAIEmbeddings\":\n        builder.Services.AddSingleton<IEmbeddingGenerator>(\n            sp => new OpenAIClient(appConfig.OpenAIEmbeddingsConfig.ApiKey)\n                .GetEmbeddingClient(appConfig.OpenAIEmbeddingsConfig.ModelId)\n                .AsIEmbeddingGenerator());\n        break;\n    default:\n        throw new NotSupportedException($\"AI Embedding Service type '{appConfig.RagConfig.AIEmbeddingService}' is not supported.\");","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/VectorStoreRAG/Program.cs#L30-L66","documentation":"VectorStoreRAG's Program.cs switches on appConfig.RagConfig.AIChatService and only supports 'AzureOpenAI' and 'OpenAI'. Any other value (including null, empty string, or a typo) falls through to the default branch and throws NotSupportedException at application startup.","triggerScenarios":"The RagConfig.AIChatService configuration value is set to a string that is not exactly 'AzureOpenAI' or 'OpenAI' (case-sensitive) — e.g., 'azureopenai', 'Azure', 'Anthropic', or null/empty.","commonSituations":"Typo or casing error in the configuration file or user secrets; the value is left empty or unset (null); an expected future provider hasn't been added yet; copy-pasting a config from another sample with a different provider naming scheme.","solutions":["Set RagConfig:AIChatService to exactly 'AzureOpenAI' or 'OpenAI' in appsettings.json or user secrets.","If you need another provider, add a new case arm to the switch and register the appropriate chat completion service.","Verify there are no trailing spaces or casing differences in the configured value.","Make the switch case-insensitive with StringComparison to reduce friction."],"exampleFix":"// before — only two providers, case-sensitive\nswitch (appConfig.RagConfig.AIChatService)\n{\n    case \"AzureOpenAI\": /* ... */ break;\n    case \"OpenAI\": /* ... */ break;\n    default:\n        throw new NotSupportedException($\"AI Chat Service type '{appConfig.RagConfig.AIChatService}' is not supported.\");\n}\n\n// after — case-insensitive with clear valid-values list\nswitch (appConfig.RagConfig.AIChatService?.ToLowerInvariant())\n{\n    case \"azureopenai\": /* ... */ break;\n    case \"openai\": /* ... */ break;\n    default:\n        throw new NotSupportedException(\n            $\"AI Chat Service type '{appConfig.RagConfig.AIChatService}' is not supported. Valid values: 'AzureOpenAI', 'OpenAI'.\");\n}","handlingStrategy":"validation","validationCode":"// Validate the value before the switch\nvar validChatServices = new[] { \"AzureOpenAI\", \"OpenAI\" };\nif (!validChatServices.Contains(appConfig.RagConfig.AIChatService))\n    throw new ArgumentException($\"AIChatService must be one of: {string.Join(\", \", validChatServices)}. Got: '{appConfig.RagConfig.AIChatService}'\");","typeGuard":"bool IsValidChatService(string? s) => s is \"AzureOpenAI\" or \"OpenAI\";","tryCatchPattern":null,"preventionTips":["Document all valid enum-like string values in configuration comments.","Consider using an actual enum or a Options<T> with validation instead of raw strings.","Make switch matching case-insensitive to reduce friction."],"tags":["configuration","not-supported","rag","vector-store","chat-completion","startup"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}