microsoft/aspire · error · NotSupportedException

Unsupported value type

Error message

Unsupported value type {val.GetType()}

What it means

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.

Solutions

  1. Convert the value to a string or FormattableString before passing it (e.g., reference.Value or interpolation).
  2. Use the resource's supported reference API (e.g., IAzureKeyVaultSecretReference, endpoint references) instead of the raw object.
  3. Upgrade (or align) Aspire.Hosting packages so value-provider types match what BaseContainerAppContext supports.

Example fix

// before
builder.AddProject<Projects.Api>("api")
    .WithEnvironment("SOME_VALUE", customValueObject);

// after
builder.AddProject<Projects.Api>("api")
    .WithEnvironment("SOME_VALUE", customValueObject.ToString());
Defensive patterns

Strategy: type-guard

Validate before calling

static bool IsSupportedContainerAppValue(object? v) =>
    v is BicepValue<string> or string or ProvisioningParameter or FormattableString;

Type guard

bool IsBicepCompatibleValue(object? v) => v is BicepValue<string> or string or ProvisioningParameter or FormattableString;

Try / catch

try { app.WithEnvironment("K", value); } catch (NotSupportedException ex) when (ex.Message.StartsWith("Unsupported value type")) { /* coerce value to string or use a supported reference */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/4d7336ff2a1b4401. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Azure.AppContainers/BaseContainerAppContext.cs:150

        {
            var context = new EnvironmentCallbackContext(_containerAppEnvironmentContext.ExecutionContext, resource, EnvironmentVariables, cancellationToken: cancellationToken);

            foreach (var c in environmentCallbacks)
            {
                await c.Callback(context).ConfigureAwait(false);
            }
        }
    }

    private static BicepValue<string> ResolveValue(object val)
    {
        return val switch
        {
            BicepValue<string> s => s,
            string s => s,
            ProvisioningParameter p => p,
            FormattableString fs => BicepFunction.Interpolate(fs),
            _ => throw new NotSupportedException("Unsupported value type " + val.GetType())
        };
    }

    private void ProcessVolumes()
    {
        if (resource.TryGetContainerMounts(out var mounts))
        {
            var bindMountIndex = 0;
            var volumeIndex = 0;

            foreach (var volume in mounts)
            {
                var (index, volumeName) = volume.Type switch
                {
                    ContainerMountType.BindMount => (bindMountIndex, $"bm{bindMountIndex}"),
                    ContainerMountType.Volume => (volumeIndex, $"v{volumeIndex}"),
                    _ => throw new NotSupportedException()
                };

View on GitHub (pinned to 25830f84bd)