{"record":{"id":"17f71db115fa58df","repo":"microsoft/aspire","slug":"the-azure-resource-scope-value-cannot-be-null","errorCode":null,"errorMessage":"The Azure resource scope value cannot be null.","messagePattern":"The Azure resource scope value cannot be null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure/Provisioning/Provisioners/BicepProvisioner.cs","lineNumber":1288,"sourceCode":"        AddDetail(\"correlation id\", failureDetails.CorrelationId);\n\n        return details.Count == 0 ? string.Empty : $\" ({string.Join(\"; \", details)})\";\n\n        void AddDetail(string name, string? value)\n        {\n            if (!string.IsNullOrEmpty(value))\n            {\n                details.Add($\"{name}: {value}\");\n            }\n        }\n    }\n\n    private static async Task<string> ResolveScopeValueAsync(object scopeValue, CancellationToken cancellationToken)\n    {\n        return scopeValue switch\n        {\n            string value => value,\n            IValueProvider valueProvider => await valueProvider.GetValueAsync(cancellationToken).ConfigureAwait(false) ?? throw new InvalidOperationException(\"The Azure resource scope value cannot be null.\"),\n            _ => throw new NotSupportedException($\"The scope value type {scopeValue.GetType()} is not supported.\")\n        };\n    }\n\n    private async Task<bool> TryCancelDeploymentAsync(IArmDeploymentCollection deployments, string deploymentName, ILogger resourceLogger, bool treatMissingOrInactiveAsCanceled)\n    {\n        try\n        {\n            await deployments.CancelAsync(deploymentName, CancellationToken.None).ConfigureAwait(false);\n            resourceLogger.LogInformation(\"Cancellation requested for Azure deployment {DeploymentName}.\", deploymentName);\n            return true;\n        }\n        catch (RequestFailedException ex) when (treatMissingOrInactiveAsCanceled && (ex.Status == 404 || ex.Status == 409))\n        {\n            logger.LogInformation(ex, \"Azure deployment {DeploymentName} was already absent or no longer active during cancellation.\", deploymentName);\n            resourceLogger.LogInformation(\"Azure deployment {DeploymentName} was already absent or no longer active during cancellation.\", deploymentName);\n            return true;\n        }","sourceCodeStart":1270,"sourceCodeEnd":1306,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure/Provisioning/Provisioners/BicepProvisioner.cs#L1270-L1306","documentation":"ResolveScopeValueAsync resolves a deployment scope value that can be a literal string or an IValueProvider. If the IValueProvider returns null after awaiting GetValueAsync, the provisioner throws InvalidOperationException because an ARM deployment cannot proceed with a null scope (subscription/resource-group target).","triggerScenarios":"A resource's scope (e.g. RunAsExisting/subscription/resource group scope via IValueProvider such as a parameter reference or output reference) resolves to null at provisioning time in ResolveScopeValueAsync.","commonSituations":"A configuration parameter or environment variable feeding the scope was not set, a referenced resource's output wasn't produced before resolution, or a custom IValueProvider implementation returned null.","solutions":["Ensure the parameter/env var backing the scope value is set before running the AppHost.","Verify the referenced resource producing the value ran and emitted its output (ordering/waiting).","Fix custom IValueProvider implementations to return a non-null scope string.","Validate the scope configuration (subscription id / resource group name) at startup."],"exampleFix":"// before\nvar scope = builder.AddParameter(\"resourceGroupName\"); // never supplied -> null value\n\n// after\ndotnet user-secrets set Parameters:resourceGroupName \"my-rg\"\n// or provide a default:\nvar scope = builder.AddParameter(\"resourceGroupName\", value: \"my-rg\");","handlingStrategy":"validation","validationCode":"if (scopeParam is IValueProvider vp)\n{\n    var v = await vp.GetValueAsync(ct);\n    if (string.IsNullOrWhiteSpace(v as string)) throw new InvalidOperationException(\"Scope value resolved to null; supply the parameter before provisioning.\");\n}","typeGuard":"static bool ResolvesToNonEmpty(IValueProvider provider) => provider.GetValueAsync(default).GetAwaiter().GetResult() is string s && s.Length > 0;","tryCatchPattern":"try\n{\n    await provisioner.GetOrCreateResourceAsync(resource, ct);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"scope value cannot be null\"))\n{\n    logger.LogError(ex, \"Deployment scope was null; check the parameter or referenced resource output supplying it.\");\n}","preventionTips":["Set all parameters feeding scope values via user-secrets/env before startup.","Ensure referenced resources complete and emit outputs before dependent provisioning.","Fail fast at startup by validating required parameters exist."],"tags":["azure","provisioning","scope","null-value"],"backgroundTag":"null-argument","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"}