{"record":{"id":"aa3b23a910f6c992","repo":"microsoft/aspire","slug":"string-format-launchprofilestrings-launchprofileextensions","errorCode":null,"errorMessage":"string.Format(LaunchProfileStrings.ProjectFileNotFoundExceptionMessage, projectMetadata.ProjectPath)","messagePattern":"string\\.Format\\(LaunchProfileStrings\\.ProjectFileNotFoundExceptionMessage, projectMetadata\\.ProjectPath\\)","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Shared/LaunchProfiles/LaunchProfileExtensions.cs","lineNumber":79,"sourceCode":"            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        }\n\n        var projectFileInfo = new FileInfo(projectMetadata.ProjectPath);\n        var launchSettingsFilePath = projectFileInfo.DirectoryName switch\n        {\n            null => Path.Combine(\"Properties\", \"launchSettings.json\"),\n            _ => Path.Combine(projectFileInfo.DirectoryName, \"Properties\", \"launchSettings.json\")\n        };\n\n        // It isn't mandatory that the launchSettings.json file exists!\n        if (!File.Exists(launchSettingsFilePath))\n        {\n            if (!projectMetadata.IsFileBasedApp)\n            {\n                return null;\n            }\n            else\n            {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Shared/LaunchProfiles/LaunchProfileExtensions.cs#L61-L97","documentation":"When reading launch settings, GetLaunchSettings(IProjectMetadata) checks that projectMetadata.ProjectPath exists on disk. If the project file is missing it throws DistributedApplicationException with ProjectFileNotFoundExceptionMessage formatted with the path. The project path is recorded when the resource was added and must still be valid when launch settings are read.","triggerScenarios":"Reading launch settings for a project resource whose IProjectMetadata.ProjectPath points to a .csproj that no longer exists — e.g. after the project file was moved, renamed, deleted, or the AppHost model was built on a different machine.","commonSituations":"Renaming/moving a project folder without updating the AppHost reference; cloning a repo without restoring all project files; generated projects removed by a clean step; path differences between Windows and Linux checkouts.","solutions":["Verify the path in the error message exists; restore or recreate the missing .csproj file.","Re-add the project in the AppHost (AddProject<T>) so ProjectPath reflects the current location.","If projects were moved, fix the solution references and rebuild the AppHost so fresh metadata is captured.","Ensure any project-generation step (e.g. tests that scaffold projects) runs before launch settings are read."],"exampleFix":"// before: projects/api/Api.csproj was deleted\nbuilder.AddProject<Projects.Api>(\"api\"); // ProjectPath stale\n\n// after: restore projects/api/Api.csproj (or move it back) and rebuild,\n// so IProjectMetadata.ProjectPath points at an existing file.","handlingStrategy":"validation","validationCode":"var projectPath = metadata.ProjectPath;\nif (!File.Exists(projectPath))\n    throw new FileNotFoundException($\"Project file for resource was moved or deleted: {projectPath}\", projectPath);","typeGuard":null,"tryCatchPattern":"try { var settings = resource.GetLaunchSettings(); }\ncatch (DistributedApplicationException ex)\n{ logger.LogError(ex, \"Project file missing at {Path}; rebuild the AppHost model\", projectPath); throw; }","preventionTips":["Never move/rename project directories without updating the AppHost and rebuilding.","Rebuild the AppHost so IProjectMetadata.ProjectPath reflects the current disk layout.","Ensure any test scaffolding that creates projects runs before code that reads launch settings."],"tags":["launch-settings","file","not-found","project"],"backgroundTag":"file-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"}