{"record":{"id":"0fbc25e204900d05","repo":"microsoft/aspire","slug":"deployment-slot-must-be-a-string-or-a-parameter-resource","errorCode":null,"errorMessage":"Deployment slot must be a string or a parameter resource builder.","messagePattern":"Deployment slot must be a string or a parameter resource builder\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentExtensions.cs","lineNumber":459,"sourceCode":"        return builder;\n    }\n\n    /// <summary>\n    /// Configures the deployment slot for all Azure App Services in the environment\n    /// </summary>\n    [AspireExport(\"withDeploymentSlot\")]\n    internal static IResourceBuilder<AzureAppServiceEnvironmentResource> WithDeploymentSlotForPolyglot(\n        this IResourceBuilder<AzureAppServiceEnvironmentResource> builder,\n        [AspireUnion(typeof(string), typeof(IResourceBuilder<ParameterResource>))] object deploymentSlot)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentNullException.ThrowIfNull(deploymentSlot);\n\n        return deploymentSlot switch\n        {\n            string deploymentSlotName => builder.WithDeploymentSlot(deploymentSlotName),\n            IResourceBuilder<ParameterResource> deploymentSlotParameter => builder.WithDeploymentSlot(deploymentSlotParameter),\n            _ => throw new ArgumentException(\"Deployment slot must be a string or a parameter resource builder.\", nameof(deploymentSlot))\n        };\n    }\n\n    /// <summary>\n    /// Configures the slot to which the Azure App Services should be deployed.\n    /// </summary>\n    /// <param name=\"builder\">The AzureAppServiceEnvironmentResource to configure.</param>\n    /// <param name=\"deploymentSlot\">The deployment slot for all App Services in the App Service Environment.</param>\n    /// <returns><see cref=\"IResourceBuilder{T}\"/></returns>\n    [AspireExportIgnore(Reason = \"Polyglot AppHosts use the internal withDeploymentSlot dispatcher export.\")]\n    public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithDeploymentSlot(this IResourceBuilder<AzureAppServiceEnvironmentResource> builder, string deploymentSlot)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrWhiteSpace(deploymentSlot);\n\n        builder.Resource.DeploymentSlot = deploymentSlot;\n        return builder;\n    }","sourceCodeStart":441,"sourceCodeEnd":477,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentExtensions.cs#L441-L477","documentation":"WithDeploymentSlotForPolyglot accepts a deployment slot specified either as a string name or as an IResourceBuilder<ParameterResource>. Any other runtime type falls into the switch discard arm and throws ArgumentException, because a slot cannot be resolved from the supplied value.","triggerScenarios":"Passing a non-string, non-parameter-builder value — e.g. a numeric slot index, a ParameterResource without its builder wrapper, custom types, or deserialized polyglot config that maps the slot to an unexpected type (object/int).","commonSituations":"Polyglot (YAML/JSON/JS) configs where the slot value was parsed as a number or object; C# callers passing a raw ParameterResource instead of its IResourceBuilder wrapper; dynamic values boxed as object with an unexpected type.","solutions":["Pass the slot name as a string, e.g. WithDeploymentSlotForPolyglot(\"staging\").","Pass an IResourceBuilder<ParameterResource> obtained from AddParameter if the slot must be parameterized.","Convert/validate the slot argument's type at the call site before invoking the API.","In polyglot configs, quote the slot value so it deserializes as a string, not a number."],"exampleFix":"// before\nenv.WithDeploymentSlotForPolyglot(2); // numeric\n// after\nenv.WithDeploymentSlotForPolyglot(\"staging\");","handlingStrategy":"type-guard","validationCode":"var ok = deploymentSlot is string or IResourceBuilder<ParameterResource>;","typeGuard":"static bool IsValidSlotArg(object? v) => v is string or IResourceBuilder<ParameterResource>;","tryCatchPattern":"try { env.WithDeploymentSlotForPolyglot(deploymentSlot); } catch (ArgumentException ex) { logger.LogError(ex, \"Deployment slot must be string or parameter builder, got {Type}\", deploymentSlot?.GetType().Name); }","preventionTips":["Quote slot names in polyglot configs so they parse as strings.","Wrap ParameterResource values in their builders.","Validate slot values at config-load time."],"tags":["azure","appservice","argument-type","polyglot"],"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"}