microsoft/semantic-kernel · critical · ConfigurationNotFoundException
Configuration key '{section}:{key}' not found
Error message
Configuration key '{section}:{key}' not found What it means
In ConfigureTracing, when useApplicationInsights is true the code reads TestConfiguration.ApplicationInsights.ConnectionString. If the value is null or whitespace, it throws ConfigurationNotFoundException(section, key) — a custom exception whose message is formatted as 'Configuration key \'{section}:{key}\' not found'. This guards against starting an Azure Monitor trace exporter with no connection string, which would fail silently or crash deep in the exporter.
Source
Thrown at dotnet/samples/GettingStartedWithAgents/Step07_Telemetry.cs:220
}
private TracerProvider? GetTracerProvider(bool useApplicationInsights)
{
// Enable diagnostics.
AppContext.SetSwitch("Microsoft.SemanticKernel.Experimental.GenAI.EnableOTelDiagnostics", true);
var tracerProviderBuilder = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("Semantic Kernel Agents Tracing Example"))
.AddSource("Microsoft.SemanticKernel*")
.AddSource(s_activitySource.Name);
if (useApplicationInsights)
{
var connectionString = TestConfiguration.ApplicationInsights.ConnectionString;
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new ConfigurationNotFoundException(
nameof(TestConfiguration.ApplicationInsights),
nameof(TestConfiguration.ApplicationInsights.ConnectionString));
}
tracerProviderBuilder.AddAzureMonitorTraceExporter(o => o.ConnectionString = connectionString);
}
else
{
tracerProviderBuilder.AddConsoleExporter();
}
return tracerProviderBuilder.Build();
}
private ILoggerFactory GetLoggerFactoryOrDefault(ILoggerFactory? loggerFactory = null) => loggerFactory ?? NullLoggerFactory.Instance;
private sealed class ApprovalTerminationStrategy : TerminationStrategy
{View on GitHub (pinned to c028a0c7dc)
Solutions
- Set the Application Insights connection string: 'dotnet user-secrets set "ApplicationInsights:ConnectionString" "<your-connection-string>"'.
- Set the environment variable ApplicationInsights__ConnectionString (double underscore for section separator).
- If you don't have Application Insights, call ConfigureTracing(useApplicationInsights: false) to use the console exporter instead.
- Verify the connection string is copied from the Azure Portal (Application Insights resource > Overview > Connection String), not the instrumentation key.
Example fix
// before
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new ConfigurationNotFoundException(
nameof(TestConfiguration.ApplicationInsights),
nameof(TestConfiguration.ApplicationInsights.ConnectionString));
}
// after — fall back to console exporter with a warning
if (string.IsNullOrWhiteSpace(connectionString))
{
Console.WriteLine("Application Insights connection string not configured; falling back to console exporter.");
tracerProviderBuilder.AddConsoleExporter();
}
else
{
tracerProviderBuilder.AddAzureMonitorTraceExporter(o => o.ConnectionString = connectionString);
} Defensive patterns
Strategy: validation
Validate before calling
// Check the connection string before configuring the exporter
var connectionString = config["ApplicationInsights:ConnectionString"];
if (useApplicationInsights && string.IsNullOrWhiteSpace(connectionString))
throw new ConfigurationNotFoundException("ApplicationInsights", "ConnectionString"); Type guard
bool HasAppInsightsConfig(IConfiguration c) => !string.IsNullOrWhiteSpace(c["ApplicationInsights:ConnectionString"]);
Try / catch
try { return ConfigureTracing(useApplicationInsights: true); } catch (ConfigurationNotFoundException) { Console.WriteLine("App Insights not configured; using console exporter."); return ConfigureTracing(useApplicationInsights: false); } Prevention
- Set ApplicationInsights:ConnectionString in user secrets or environment before enabling the exporter.
- Use the connection string from the Azure Portal (not the instrumentation key).
- Fall back to the console exporter when the connection string is absent in development.
When it happens
Trigger: Calling ConfigureTracing(useApplicationInsights: true) when the ApplicationInsights:ConnectionString configuration key is absent — i.e., it wasn't set in user secrets, environment variables, or appsettings.json.
Common situations: Switching from console exporter to Application Insights exporter without configuring the connection string; CI environment missing the APPINSIGHTS_CONNECTIONSTRING or ApplicationInsights__ConnectionString variable; user secrets not set for the connection string; the TestConfiguration static initialization didn't pick up the section.
Related errors
- OpenAI/Azure OpenAI configuration was not found.
- Could not find configuration section {caller}
- AI Chat Service type '{appConfig.RagConfig.AIChatService}' i
- AI Embedding Service type '{appConfig.RagConfig.AIEmbeddingS
- Vector store type '{appConfig.RagConfig.VectorStoreType}' is
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/f5d93615cf05250d.
Report an issue: GitHub.