{"record":{"id":"4d7336ff2a1b4401","repo":"microsoft/aspire","slug":"unsupported-value-type-val-gettype","errorCode":null,"errorMessage":"Unsupported value type {val.GetType()}","messagePattern":"Unsupported value type (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppContainers/BaseContainerAppContext.cs","lineNumber":150,"sourceCode":"        {\n            var context = new EnvironmentCallbackContext(_containerAppEnvironmentContext.ExecutionContext, resource, EnvironmentVariables, cancellationToken: cancellationToken);\n\n            foreach (var c in environmentCallbacks)\n            {\n                await c.Callback(context).ConfigureAwait(false);\n            }\n        }\n    }\n\n    private static BicepValue<string> ResolveValue(object val)\n    {\n        return val switch\n        {\n            BicepValue<string> s => s,\n            string s => s,\n            ProvisioningParameter p => p,\n            FormattableString fs => BicepFunction.Interpolate(fs),\n            _ => throw new NotSupportedException(\"Unsupported value type \" + val.GetType())\n        };\n    }\n\n    private void ProcessVolumes()\n    {\n        if (resource.TryGetContainerMounts(out var mounts))\n        {\n            var bindMountIndex = 0;\n            var volumeIndex = 0;\n\n            foreach (var volume in mounts)\n            {\n                var (index, volumeName) = volume.Type switch\n                {\n                    ContainerMountType.BindMount => (bindMountIndex, $\"bm{bindMountIndex}\"),\n                    ContainerMountType.Volume => (volumeIndex, $\"v{volumeIndex}\"),\n                    _ => throw new NotSupportedException()\n                };","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppContainers/BaseContainerAppContext.cs#L132-L168","documentation":"BaseContainerAppContext.ResolveValue converts environment-variable/argument values into Bicep expressions when generating Container App infrastructure. It only supports BicepValue<string>, string, ProvisioningParameter, and FormattableString; anything else falls through to this NotSupportedException. It indicates a value type reached container-app Bicep generation that has no mapping.","triggerScenarios":"Passing an unsupported object type (e.g., a custom IResourceBuilder value, ConnectionStringReference-like object, or other IManifestExpressionProvider variant not handled upstream) into a container app's environment variables, args, or command line via WithEnvironment/WithArgs.","commonSituations":"Using a value provider type from a newer/older Aspire version that BaseContainerAppContext doesn't map; passing a reference to a resource type that emits an unsupported output expression; custom resources producing exotic parameter types.","solutions":["Convert the value to a string or FormattableString before passing it (e.g., reference.Value or interpolation).","Use the resource's supported reference API (e.g., IAzureKeyVaultSecretReference, endpoint references) instead of the raw object.","Upgrade (or align) Aspire.Hosting packages so value-provider types match what BaseContainerAppContext supports."],"exampleFix":"// before\nbuilder.AddProject<Projects.Api>(\"api\")\n    .WithEnvironment(\"SOME_VALUE\", customValueObject);\n\n// after\nbuilder.AddProject<Projects.Api>(\"api\")\n    .WithEnvironment(\"SOME_VALUE\", customValueObject.ToString());","handlingStrategy":"type-guard","validationCode":"static bool IsSupportedContainerAppValue(object? v) =>\n    v is BicepValue<string> or string or ProvisioningParameter or FormattableString;","typeGuard":"bool IsBicepCompatibleValue(object? v) => v is BicepValue<string> or string or ProvisioningParameter or FormattableString;","tryCatchPattern":"try { app.WithEnvironment(\"K\", value); } catch (NotSupportedException ex) when (ex.Message.StartsWith(\"Unsupported value type\")) { /* coerce value to string or use a supported reference */ }","preventionTips":["Pass strings, FormattableStrings, or resource reference APIs into WithEnvironment/WithArgs.","Avoid custom IValueProvider implementations for container apps.","Keep Aspire.Hosting.* packages on matching versions."],"tags":["azure","container-apps","bicep","type-mismatch"],"backgroundTag":"unsupported-enum-value","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"}