{"record":{"id":"b08992380e46e2a2","repo":"microsoft/aspire","slug":"the-azure-scope-value-type-value-gettype-is-not-supported","errorCode":null,"errorMessage":"The Azure scope value type {value.GetType()} is not supported.","messagePattern":"The Azure scope value type (.+?) is not supported\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentResource.AksPipeline.cs","lineNumber":809,"sourceCode":"    /// <remarks>\n    /// Matches <c>BicepProvisioner.ResolveScopeValueAsync</c>, including its refusal to accept a\n    /// null result from a provider. Falling back to the app's own subscription in that case would\n    /// be worse than failing: provisioning would have thrown, while the credential fetch would\n    /// quietly target the wrong scope and could adopt a same-named cluster there. Empty is rejected\n    /// for the same reason, since the string.IsNullOrEmpty checks downstream would treat it as\n    /// unpinned. Nothing upstream rejects empty (the scope constructors and\n    /// <c>AsExistingInResourceGroup</c> only guard against null), so a literal is checked too.\n    /// </remarks>\n    internal static async Task<string?> ResolveScopeValueAsync(object? value, CancellationToken cancellationToken)\n        => value switch\n        {\n            null => null,\n            string { Length: > 0 } s => s,\n            IValueProvider provider when\n                await provider.GetValueAsync(cancellationToken).ConfigureAwait(false) is { Length: > 0 } resolved => resolved,\n            string or IValueProvider => throw new InvalidOperationException(\n                \"The Azure resource scope value cannot be null or empty.\"),\n            _ => throw new NotSupportedException(\n                $\"The Azure scope value type {value.GetType()} is not supported.\")\n        };\n\n    /// <summary>\n    /// Resolves the subscription and resource group that this AKS cluster actually lives in.\n    /// </summary>\n    /// <remarks>\n    /// A cluster adopted with <c>AsExistingInResourceGroup(...)</c> can sit in a different\n    /// subscription and resource group than the one Aspire deploys the rest of the app into, and the\n    /// provisioner targets that per-resource scope. The Azure CLI calls here have to agree with it,\n    /// otherwise we would authenticate against the wrong subscription and could even find a\n    /// same-named cluster in the wrong place. Values the resource does not pin fall back to the\n    /// global deployment state.\n    /// </remarks>\n    internal static async Task<(string SubscriptionId, string? ResourceGroup)> ResolveDeploymentScopeAsync(\n        object? scopedSubscription,\n        object? scopedResourceGroup,\n        IServiceProvider services,","sourceCodeStart":791,"sourceCodeEnd":827,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentResource.AksPipeline.cs#L791-L827","documentation":"ResolveScopeValueAsync received a scope value whose runtime type is neither string nor IValueProvider, so it cannot be resolved. This is a programming/API-misuse error: an unsupported object was passed where a scope (subscription ID or resource group) is expected.","triggerScenarios":"Calling the scope-configuration API with an arbitrary object (e.g. a resource reference, GUID, or custom type) instead of a string or IValueProvider.","commonSituations":"Passing a ParameterResource's Value object or an EndpointReference directly instead of the resource itself; refactoring left a variable of the wrong type; confusion between resource and value in the API.","solutions":["Pass a string literal or variable of type string for the subscription ID / resource group","Pass an IValueProvider (e.g. a ParameterResource) instead of an unrelated object","Fix the variable's declared type at the call site so the compiler enforces string/IValueProvider","Check the API's XML docs for the accepted scope value types"],"exampleFix":"// before\n// Guid subId = Guid.NewGuid();\n// aks.WithScope(subId, resourceGroup); // unsupported type\n// after\n// string subId = \"00000000-0000-0000-0000-000000000000\";\n// aks.WithScope(subId, resourceGroup);","handlingStrategy":"type-guard","validationCode":"bool IsValidScope(object? v) => v is string { Length: > 0 } or IValueProvider;","typeGuard":"static bool IsValidScopeValue(object value) =>\n    value is string { Length: > 0 } or IValueProvider;","tryCatchPattern":null,"preventionTips":["Declare scope variables as string or IValueProvider so the compiler catches misuse","Read the API docs for accepted scope value types","Pass the parameter resource itself, not its resolved Value or unrelated references"],"tags":["azure","scope","type-mismatch","api-misuse"],"backgroundTag":"type-mismatch","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"}