{"record":{"id":"e8d197863b35e64d","repo":"microsoft/aspire","slug":"cannot-configure-custom-domain-when-resource-is-not-parented","errorCode":null,"errorMessage":"Cannot configure custom domain when resource is not parented by ResourceModuleConstruct.","messagePattern":"Cannot configure custom domain when resource is not parented by ResourceModuleConstruct\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppContainers/ContainerAppExtensions.cs","lineNumber":66,"sourceCode":"    /// builder.AddProject&lt;Projects.InventoryService&gt;(\"inventory\")\n    ///        .PublishAsAzureContainerApp((module, app) =>\n    ///        {\n    ///          app.ConfigureCustomDomain(customDomain, certificateName);\n    ///        });\n    /// </code>\n    /// </example>\n    /// </remarks>\n    /// <ats-remarks />\n    [AspireExport]\n    public static void ConfigureCustomDomain(this ContainerApp app, IResourceBuilder<ParameterResource> customDomain, IResourceBuilder<ParameterResource> certificateName)\n    {\n        ArgumentNullException.ThrowIfNull(app);\n        ArgumentNullException.ThrowIfNull(customDomain);\n        ArgumentNullException.ThrowIfNull(certificateName);\n\n        if (app.ParentInfrastructure is not AzureResourceInfrastructure module)\n        {\n            throw new ArgumentException(\"Cannot configure custom domain when resource is not parented by ResourceModuleConstruct.\", nameof(app));\n        }\n\n        var containerAppManagedEnvironmentId = app.EnvironmentId;\n        var certificateNameParameter = certificateName.AsProvisioningParameter(module);\n        var customDomainParameter = customDomain.AsProvisioningParameter(module);\n\n        var bindingTypeConditional = new ConditionalExpression(\n            new BinaryExpression(\n                new IdentifierExpression(certificateNameParameter.BicepIdentifier),\n                BinaryBicepOperator.NotEqual,\n                new StringLiteralExpression(string.Empty)),\n            new StringLiteralExpression(\"SniEnabled\"),\n            new StringLiteralExpression(\"Disabled\")\n            );\n\n        var certificateOrEmpty = new ConditionalExpression(\n            new BinaryExpression(\n                new IdentifierExpression(certificateNameParameter.BicepIdentifier),","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppContainers/ContainerAppExtensions.cs#L48-L84","documentation":"WithCustomDomain-related configuration (ConfigureCustomDomain) emits Bicep parameters via the resource's parent AzureResourceInfrastructure. If the container app was not created inside a ResourceModuleConstruct-based infrastructure, there is no module to attach the certificate/custom domain parameters to, so an ArgumentException is thrown.","triggerScenarios":"Calling the custom domain extension on a container app whose ParentInfrastructure is not an AzureResourceInfrastructure (e.g. customization callback running against a construct that isn't a ResourceModuleConstruct, or calling outside a publish customization).","commonSituations":"Using ConfigureCustomDomain in Run mode or in a context where the app isn't part of a publishable module; wrapping the container app in a custom infrastructure type that isn't ResourceModuleConstruct.","solutions":["Ensure the container app is published through a ResourceModuleConstruct (standard Azure publish flow) before configuring a custom domain","Move the custom domain configuration into the proper publish-time customization callback","Verify you are not calling the API at run time; custom domains only apply to published Azure resources"],"exampleFix":"// before\nvar app = builder.AddProject<Projects.Api>(\"api\");\nConfigureCustomDomain(app, domain, certName); // called outside module construct\n// after\nbuilder.AddProject<Projects.Api>(\"api\")\n    .PublishAsAzureContainerApp(env, app => ConfigureCustomDomain(app, domain, certName));","handlingStrategy":"validation","validationCode":"if (app.ParentInfrastructure is AzureResourceInfrastructure module)\n{\n    // safe to call ConfigureCustomDomain\n}","typeGuard":"bool canConfigureCustomDomain = app.ParentInfrastructure is AzureResourceInfrastructure;","tryCatchPattern":"try { ConfigureCustomDomain(app, domain, certName); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"ResourceModuleConstruct\")) { /* app is not in a publishable module */ }","preventionTips":["Configure custom domains only inside publish-time customization callbacks","Do not call publish-only extensions in Run mode","Verify the infrastructure type hosting the app before emitting Bicep parameters"],"tags":["azure","container-apps","custom-domain","publish"],"backgroundTag":"invalid-argument-value","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"}