microsoft/semantic-kernel · critical · NotSupportedException
AI Chat Service type '{appConfig.RagConfig.AIChatService}' i
Error message
AI Chat Service type '{appConfig.RagConfig.AIChatService}' is not supported. What it means
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.
Source
Thrown at dotnet/samples/Demos/VectorStoreRAG/Program.cs:48
// and add Chat Completion and Text Embedding Generation services.
var kernelBuilder = builder.Services.AddKernel();
switch (appConfig.RagConfig.AIChatService)
{
case "AzureOpenAI":
kernelBuilder.AddAzureOpenAIChatCompletion(
appConfig.AzureOpenAIConfig.ChatDeploymentName,
appConfig.AzureOpenAIConfig.Endpoint,
new AzureCliCredential());
break;
case "OpenAI":
kernelBuilder.AddOpenAIChatCompletion(
appConfig.OpenAIConfig.ModelId,
appConfig.OpenAIConfig.ApiKey,
appConfig.OpenAIConfig.OrgId);
break;
default:
throw new NotSupportedException($"AI Chat Service type '{appConfig.RagConfig.AIChatService}' is not supported.");
}
switch (appConfig.RagConfig.AIEmbeddingService)
{
case "AzureOpenAIEmbeddings":
builder.Services.AddSingleton<IEmbeddingGenerator>(
sp => new AzureOpenAIClient(new Uri(appConfig.AzureOpenAIEmbeddingsConfig.Endpoint), new AzureCliCredential())
.GetEmbeddingClient(appConfig.AzureOpenAIEmbeddingsConfig.DeploymentName)
.AsIEmbeddingGenerator());
break;
case "OpenAIEmbeddings":
builder.Services.AddSingleton<IEmbeddingGenerator>(
sp => new OpenAIClient(appConfig.OpenAIEmbeddingsConfig.ApiKey)
.GetEmbeddingClient(appConfig.OpenAIEmbeddingsConfig.ModelId)
.AsIEmbeddingGenerator());
break;
default:
throw new NotSupportedException($"AI Embedding Service type '{appConfig.RagConfig.AIEmbeddingService}' is not supported.");View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before — only two providers, case-sensitive
switch (appConfig.RagConfig.AIChatService)
{
case "AzureOpenAI": /* ... */ break;
case "OpenAI": /* ... */ break;
default:
throw new NotSupportedException($"AI Chat Service type '{appConfig.RagConfig.AIChatService}' is not supported.");
}
// after — case-insensitive with clear valid-values list
switch (appConfig.RagConfig.AIChatService?.ToLowerInvariant())
{
case "azureopenai": /* ... */ break;
case "openai": /* ... */ break;
default:
throw new NotSupportedException(
$"AI Chat Service type '{appConfig.RagConfig.AIChatService}' is not supported. Valid values: 'AzureOpenAI', 'OpenAI'.");
} Defensive patterns
Strategy: validation
Validate before calling
// Validate the value before the switch
var validChatServices = new[] { "AzureOpenAI", "OpenAI" };
if (!validChatServices.Contains(appConfig.RagConfig.AIChatService))
throw new ArgumentException($"AIChatService must be one of: {string.Join(", ", validChatServices)}. Got: '{appConfig.RagConfig.AIChatService}'"); Type guard
bool IsValidChatService(string? s) => s is "AzureOpenAI" or "OpenAI";
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- AI Embedding Service type '{appConfig.RagConfig.AIEmbeddingS
- Vector store type '{appConfig.RagConfig.VectorStoreType}' is
- OpenAI/Azure OpenAI configuration was not found.
- Could not find configuration section {caller}
- Configuration key '{section}:{key}' not found
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/e8d7becc7cad87cf.
Report an issue: GitHub.