{"record":{"id":"98df5d295ef50c5e","repo":"microsoft/aspire","slug":"string-format-launchprofilestrings","errorCode":null,"errorMessage":"string.Format(LaunchProfileStrings.LaunchSettingsFileDoesNotContainProfileExceptionMessage, launchProfileName)","messagePattern":"string\\.Format\\(LaunchProfileStrings\\.LaunchSettingsFileDoesNotContainProfileExceptionMessage, launchProfileName\\)","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Shared/LaunchProfiles/LaunchProfileExtensions.cs","lineNumber":62,"sourceCode":"            return null;\n        }\n\n        return new NamedLaunchProfile(launchProfileName, launchProfile);\n    }\n\n    internal static LaunchProfile? GetLaunchProfile(this IResource projectResource, string launchProfileName, bool throwIfNotFound = false)\n    {\n        var profiles = projectResource.GetLaunchSettings()?.Profiles;\n        if (profiles is null)\n        {\n            return null;\n        }\n\n        var found = profiles.TryGetValue(launchProfileName, out var launchProfile);\n        if (!found && throwIfNotFound)\n        {\n            var message = string.Format(CultureInfo.InvariantCulture, LaunchProfileStrings.LaunchSettingsFileDoesNotContainProfileExceptionMessage, launchProfileName);\n            throw new DistributedApplicationException(message);\n        }\n\n        return launchProfile;\n    }\n\n    private static LaunchSettings? GetLaunchSettings(this IProjectMetadata projectMetadata, string resourceName)\n    {\n        // For testing\n        if (projectMetadata.LaunchSettings is { } launchSettings)\n        {\n            return launchSettings;\n        }\n\n        if (!File.Exists(projectMetadata.ProjectPath))\n        {\n            var message = string.Format(CultureInfo.InvariantCulture, LaunchProfileStrings.ProjectFileNotFoundExceptionMessage, projectMetadata.ProjectPath);\n            throw new DistributedApplicationException(message);\n        }","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Shared/LaunchProfiles/LaunchProfileExtensions.cs#L44-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nbuilder.AddProject<Projects.Api>(\"api\").WithLaunchProfile(\"https-stale\");\n\n// after\nbuilder.AddProject<Projects.Api>(\"api\").WithLaunchProfile(\"https\"); // profile exists in launchSettings.json","handlingStrategy":"try-catch","validationCode":"var settings = resource.GetLaunchSettings();\nif (settings?.Profiles.ContainsKey(profileName) != true)\n{\n    // profile absent — fall back or surface a clear error before calling GetLaunchProfile(throwIfNotFound: true)\n}","typeGuard":null,"tryCatchPattern":"try { var p = resource.GetLaunchProfile(name, throwIfNotFound: true); }\ncatch (DistributedApplicationException ex)\n{ logger.LogError(ex, \"Launch profile '{Profile}' not found in launchSettings.json\", name); }","preventionTips":["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."],"tags":["launch-settings","profile","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}