{"record":{"id":"a11cd8bf7d9e9178","repo":"microsoft/aspire","slug":"the-scope-value-type-scopevalue-gettype-is-not-supported","errorCode":null,"errorMessage":"The scope value type {scopeValue.GetType()} is not supported.","messagePattern":"The scope value type (.+?) is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure/Provisioning/Provisioners/BicepProvisioner.cs","lineNumber":1289,"sourceCode":"\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        }\n        catch (RequestFailedException ex)","sourceCodeStart":1271,"sourceCodeEnd":1307,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure/Provisioning/Provisioners/BicepProvisioner.cs#L1271-L1307","documentation":"ResolveScopeValueAsync supports only string and IValueProvider scope values; any other object type hits the NotSupportedException fallback arm. The message includes the concrete runtime type so developers know what leaked into the scope property.","triggerScenarios":"Assigning an unsupported object (e.g. an endpoint reference, custom wrapper type, or IResource instead of an IValueProvider/string) to a resource's scope setting consumed by ResolveScopeValueAsync.","commonSituations":"Passing a strongly-typed value (ResourceId, URI object, builder expression) where a string or IValueProvider is expected; upgrading Aspire where scope APIs tightened; hand-written custom scope types.","solutions":["Convert the value to a string before assigning it as the scope (e.g. .ToString() or reference type/value provider helpers).","Use builder.CreateResourceBuilder/parameter references so the scope is an IValueProvider instead of a raw object.","If using a custom value type, implement IValueProvider (or wrap it in one) so it resolves via GetValueAsync.","Check the reported type name in the message and map it to the supported string/IValueProvider forms."],"exampleFix":"// before\nresource.Scope = new ResourceId(\"/subscriptions/...\"); // unsupported type\n\n// after\nresource.Scope = \"/subscriptions/.../resourceGroups/rg\"; // or an IValueProvider","handlingStrategy":"type-guard","validationCode":"static bool IsSupportedScopeValue(object? value) => value is string or IValueProvider;","typeGuard":"static string? ResolveScopeSync(object scopeValue) => scopeValue switch\n{\n    string s => s,\n    IValueProvider vp => vp.GetValueAsync(default).GetAwaiter().GetResult() as string,\n    _ => null\n};","tryCatchPattern":"try\n{\n    await provisioner.GetOrCreateResourceAsync(resource, ct);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"scope value type\"))\n{\n    logger.LogError(ex, \"Unsupported scope type assigned; use a string or IValueProvider.\");\n}","preventionTips":["Only assign strings or IValueProvider instances to scope settings.","Convert typed identifiers (ResourceIds, URIs) to strings before assignment.","For dynamic values, wrap them in an IValueProvider implementation."],"tags":["azure","provisioning","scope","type-mismatch"],"backgroundTag":"unsupported-operation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}