microsoft/aspire · error · DistributedApplicationException
string.Format(LaunchProfileStrings.LaunchSettingsFileDoesNot…
Error message
string.Format(LaunchProfileStrings.LaunchSettingsFileDoesNotContainProfileExceptionMessage, launchProfileName)
What it means
GetLaunchProfile looks up the named profile in the resource's launchSettings.json profiles. When the profile name is not found and throwIfNotFound is true, it throws DistributedApplicationException with LaunchSettingsFileDoesNotContainProfileExceptionMessage formatted with the requested profile name.
Solutions
- Open the project's Properties/launchSettings.json and use one of the existing profile names, or add the missing profile.
- Check for a LaunchProfileAnnotation/WithLaunchProfile call naming a stale profile and update it.
- If the profile is genuinely optional, call with throwIfNotFound: false and handle null.
- Verify you are reading the right project's launch settings (each project resource has its own file).
Example fix
// before
builder.AddProject<Projects.Api>("api").WithLaunchProfile("https-stale");
// after
builder.AddProject<Projects.Api>("api").WithLaunchProfile("https"); // profile exists in launchSettings.json Defensive patterns
Strategy: try-catch
Validate before calling
var settings = resource.GetLaunchSettings();
if (settings?.Profiles.ContainsKey(profileName) != true)
{
// profile absent — fall back or surface a clear error before calling GetLaunchProfile(throwIfNotFound: true)
} Try / catch
try { var p = resource.GetLaunchProfile(name, throwIfNotFound: true); }
catch (DistributedApplicationException ex)
{ logger.LogError(ex, "Launch profile '{Profile}' not found in launchSettings.json", name); } Prevention
- Keep profile names in WithLaunchProfile/LaunchProfileAnnotation in sync with each project's launchSettings.json.
- Log available profile names from GetLaunchSettings().Profiles.Keys when a lookup misses.
- Use throwIfNotFound: false when a missing profile is an acceptable fallback case.
When it happens
Trigger: Calling resource.GetLaunchProfile(name, throwIfNotFound: true) (or GetEffectiveLaunchProfile with throwIfNotFound) where the launchSettings.json for the project exists but contains no profile with that exact name.
Common situations: Passing the apphost's profile name for a service project whose launchSettings.json has different profiles; renaming/deleting a profile in Visual Studio while code still references the old name; CI agents where profiles were pruned.
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
- Browser profile ' ' was not found under ' '. Specify the…
- string.Format(LaunchProfileStrings.ProjectFileNotFoundExcept…
- Browser profile ' ' matched multiple Chromium profiles…
- BrowserMessageStrings.BrowserLogsEmptyProfileConfiguration
- Could not resolve resource group for AKS cluster
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/98df5d295ef50c5e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Shared/LaunchProfiles/LaunchProfileExtensions.cs:62
return null;
}
return new NamedLaunchProfile(launchProfileName, launchProfile);
}
internal static LaunchProfile? GetLaunchProfile(this IResource projectResource, string launchProfileName, bool throwIfNotFound = false)
{
var profiles = projectResource.GetLaunchSettings()?.Profiles;
if (profiles is null)
{
return null;
}
var found = profiles.TryGetValue(launchProfileName, out var launchProfile);
if (!found && throwIfNotFound)
{
var message = string.Format(CultureInfo.InvariantCulture, LaunchProfileStrings.LaunchSettingsFileDoesNotContainProfileExceptionMessage, launchProfileName);
throw new DistributedApplicationException(message);
}
return launchProfile;
}
private static LaunchSettings? GetLaunchSettings(this IProjectMetadata projectMetadata, string resourceName)
{
// For testing
if (projectMetadata.LaunchSettings is { } launchSettings)
{
return launchSettings;
}
if (!File.Exists(projectMetadata.ProjectPath))
{
var message = string.Format(CultureInfo.InvariantCulture, LaunchProfileStrings.ProjectFileNotFoundExceptionMessage, projectMetadata.ProjectPath);
throw new DistributedApplicationException(message);
}View on GitHub (pinned to 25830f84bd)