microsoft/aspire · error · InvalidOperationException
The configured launch profile
Error message
The configured launch profile, '{launchProfileName}', was not found in the launch settings file. What it means
Thrown by DistributedApplicationFactory's PostConfigureBuilderOptions when the launch profile name configured via DistributedApplicationTestingOptions or TestingBuilderOptions does not exist in the project's launchSettings.json. The factory resolves the target project's launch profiles at startup and requires the configured name to match one exactly.
Solutions
- Open the test project's Properties/launchSettings.json and verify the configured profile name matches a key exactly (case-sensitive).
- Remove the explicit launch profile argument/option to let the factory pick the first available profile.
- Add the missing profile to launchSettings.json with the required environment variables and applicationUrl.
- If running in CI, ensure launchSettings.json is included in the build output (it should be copied via the default globbing) or don't rely on a custom profile.
Example fix
// before
var appHost = await DistributedApplicationTesting.CreateAsync<Projects.AspireApp_AppHost>("prod-like");
// after
var appHost = await DistributedApplicationTesting.CreateAsync<Projects.AspireApp_AppHost>("http"); // 'http' exists in launchSettings.json Defensive patterns
Strategy: validation
Validate before calling
var launchSettingsPath = Path.Combine(appHostProjectDir, "Properties", "launchSettings.json");
var profiles = JsonDocument.Parse(File.ReadAllText(launchSettingsPath)).RootElement.GetProperty("profiles")
.EnumerateObject().Select(p => p.Name).ToHashSet();
if (!profiles.Contains(options.LaunchProfileName))
throw new InvalidOperationException($"Profile '{options.LaunchProfileName}' not in launchSettings.json. Available: {string.Join(", ", profiles)}"); Prevention
- Keep launch profile names in a shared constant referenced by both launchSettings.json-adjacent tooling and tests.
- Don't rely on custom launch profiles in CI; use the default first profile.
- After renaming a profile in launchSettings.json, grep the test suite for the old name.
When it happens
Trigger: Calling DistributedApplicationTesting.CreateAsync<TEntryPoint>("my-profile") or setting options.LaunchProfileName to a name that is not a key in the test project's Properties/launchSettings.json.
Common situations: Typos or case mismatches in the profile name; renaming a profile in launchSettings.json without updating tests; CI environments where launchSettings.json is absent so only defaults exist; copying tests between projects with different profile names.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- The dashboard is not enabled for this application.
- A BlobServiceClient could not be configured. Ensure valid…
- A BlobServiceClient could not be configured. Ensure valid…
- A ChatCompletionsClient could not be configured. Ensure…
- A Container could not be configured. Ensure valid…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/7888b0b95863b69b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs:294
var launchProfileName = existingConfig["DOTNET_LAUNCH_PROFILE"];
// Load the launch profile and populate configuration with environment variables.
if (appHostLaunchSettings is not null)
{
var launchProfiles = appHostLaunchSettings.Profiles;
LaunchProfile? launchProfile;
if (string.IsNullOrEmpty(launchProfileName))
{
// If a launch profile was not specified, select the first launch profile.
var firstLaunchProfile = launchProfiles.FirstOrDefault();
launchProfile = firstLaunchProfile.Value;
SetDefault("DOTNET_LAUNCH_PROFILE", firstLaunchProfile.Key);
}
else
{
if (!launchProfiles.TryGetValue(launchProfileName, out launchProfile))
{
throw new InvalidOperationException($"The configured launch profile, '{launchProfileName}', was not found in the launch settings file.");
}
}
// Populate config from env vars.
if (launchProfile?.EnvironmentVariables is { Count: > 0 } envVars)
{
foreach (var (key, value) in envVars)
{
SetDefault(key, value);
// See https://github.com/dotnet/runtime/blob/8edaf7460777e791b6279b395a68a77533db2d20/src/libraries/Microsoft.Extensions.Hosting/src/HostApplicationBuilder.cs#L96
if (key.StartsWith("DOTNET_", StringComparison.OrdinalIgnoreCase))
{
SetDefault(key["DOTNET_".Length..], value);
}
// See https://github.com/dotnet/aspnetcore/blob/4ce2db7b8d85c07cad2c59242edc19af6a91b0d7/src/DefaultBuilder/src/WebApplicationBuilder.cs#L38
if (key.StartsWith("ASPNETCORE_", StringComparison.OrdinalIgnoreCase))View on GitHub (pinned to 25830f84bd)