{"record":{"id":"e6e1b254714e5b52","repo":"microsoft/aspire","slug":"launch-profile-must-be-a-string-or-projectresourceoptions","errorCode":null,"errorMessage":"Launch profile must be a string or ProjectResourceOptions.","messagePattern":"Launch profile must be a string or ProjectResourceOptions\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs","lineNumber":130,"sourceCode":"    /// Adds a .NET project resource\n    /// </summary>\n    [AspireExport(\"addProject\")]\n    internal static IResourceBuilder<ProjectResource> AddProjectForPolyglot(\n        this IDistributedApplicationBuilder builder,\n        [ResourceName] string name,\n        string projectPath,\n        [AspireUnion(typeof(string), typeof(ProjectResourceOptions))] object? launchProfileOrOptions = null)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrEmpty(name);\n        ArgumentNullException.ThrowIfNull(projectPath);\n\n        return launchProfileOrOptions switch\n        {\n            null => builder.AddProject(name, projectPath),\n            string launchProfileName => builder.AddProject(name, projectPath, launchProfileName),\n            ProjectResourceOptions options => builder.AddProject(name, projectPath, configure => ApplyProjectResourceOptions(configure, options)),\n            _ => throw new ArgumentException(\"Launch profile must be a string or ProjectResourceOptions.\", nameof(launchProfileOrOptions))\n        };\n    }\n\n    /// <summary>\n    /// Adds a .NET project to the application model. By default, this will exist in a Projects namespace. e.g. Projects.MyProject.\n    /// If the project is not in a Projects namespace, make sure a project reference is added from the AppHost project to the target project.\n    /// </summary>\n    /// <typeparam name=\"TProject\">A type that represents the project reference.</typeparam>\n    /// <param name=\"builder\">The <see cref=\"IDistributedApplicationBuilder\"/>.</param>\n    /// <param name=\"name\">The name of the resource. This name will be used for service discovery when referenced in a dependency.</param>\n    /// <param name=\"launchProfileName\">The launch profile to use. If <c>null</c> then no launch profile will be used.</param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{T}\"/>.</returns>\n    /// <remarks>\n    /// <para>\n    /// This overload of the <see cref=\"AddProject{TProject}(IDistributedApplicationBuilder, string)\"/> method takes\n    /// a <typeparamref name=\"TProject\"/> type parameter. The <typeparamref name=\"TProject\"/> type parameter is constrained\n    /// to types that implement the <see cref=\"IProjectMetadata\"/> interface.\n    /// </para>","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L112-L148","documentation":"AddProjectForPolyglot throws ArgumentException ( paramName launchProfileOrOptions) when the launch profile argument is neither null, a string, nor a ProjectResourceOptions instance. The method uses a switch expression over the argument; any other object type falls into the discard arm and fails fast. It exists to accept a launch profile name or options object; anything else is a caller type error.","triggerScenarios":"Passing an unsupported type as launchProfileOrOptions, e.g. an int, a LaunchSettingsProfile object, or some other custom type instead of string or ProjectResourceOptions.","commonSituations":"Refactoring code where a profile object was passed instead of its name, or overload-resolution confusion where a caller assumed a richer type was accepted.","solutions":["Pass a string launch profile name, a ProjectResourceOptions instance, or null.","If you have a profile object, pass its Name string instead.","Use ProjectResourceOptions with the configurator callback for advanced settings."],"exampleFix":"// before\nbuilder.AddProjectForPolyglot(\"api\", projectPath, someProfileObject);\n\n// after\nbuilder.AddProjectForPolyglot(\"api\", projectPath, someProfileObject.Name);\n// or\nbuilder.AddProjectForPolyglot(\"api\", projectPath, new ProjectResourceOptions { ... });","handlingStrategy":"validation","validationCode":"if (launchProfileOrOptions is not null && launchProfileOrOptions is not string && launchProfileOrOptions is not ProjectResourceOptions)\n{\n    throw new ArgumentException(\"Launch profile must be a string or ProjectResourceOptions.\", nameof(launchProfileOrOptions));\n}","typeGuard":"bool isValidLaunchProfileArg(object? arg) => arg is null or string or ProjectResourceOptions;","tryCatchPattern":"try\n{\n    builder.AddProjectForPolyglot(name, path, launchProfileOrOptions);\n}\ncatch (ArgumentException ex) when (ex.ParamName == nameof(launchProfileOrOptions))\n{\n    logger.LogError(ex, \"Invalid launch profile argument type: {Type}\", launchProfileOrOptions?.GetType().Name);\n}","preventionTips":["Only pass string, ProjectResourceOptions, or null for this parameter.","Convert profile objects to their Name strings before calling.","Check the AddProjectForPolyglot XML docs for the accepted overloads."],"tags":["argument-type","projects","apphost"],"backgroundTag":"type-mismatch","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}