An Azure service that provides hosted, universal storage for Azure app configurations.
Wrap the Azure App Configuration provider registration in a try/catch and fall back to other configuration sources when DefaultAzureCredential (or any TokenCredential) throws CredentialUnavailableException.
optional on AddAzureAppConfiguration controls failures when connecting to the store (for example, endpoint not reachable), but not failures thrown by the credential itself. DefaultAzureCredential throws CredentialUnavailableException when no credential in the chain can authenticate, and that exception must be handled explicitly.
Example:
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
var builder = new ConfigurationBuilder();
try
{
builder.AddAzureAppConfiguration(options =>
{
var endpoint = new Uri($"https://{configServer}.azconfig.io");
options.Connect(endpoint, new DefaultAzureCredential(credentialOptions));
});
}
catch (CredentialUnavailableException)
{
// Ignore and rely on other configuration providers when offline
}
var config = builder.Build();
For production, consider replacing DefaultAzureCredential with a deterministic credential (for example, ManagedIdentityCredential) and using DefaultAzureCredential only for local development, as recommended in the authentication best practices.
References: