microsoft/aspire · error · NotSupportedException

Unsupported value type

Error message

Unsupported value type {value.GetType()}

What it means

ProcessValue in BaseContainerAppContext exhaustively maps supported value shapes (outputs, parameters, secret references, endpoint references, generic IManifestExpressionProvider, etc.) into Bicep parameters. If none match, it throws this NotSupportedException, meaning an unhandled value type was supplied to a container app's environment variables, args, or command line during publish.

Solutions

  1. Convert the value to a supported type (string, FormattableString, or a resource's built-in reference type) before passing it.
  2. Use the resource's documented reference APIs (e.g., endpoint .Url/.Host, key vault secret references) rather than custom wrappers.
  3. Align package versions across Aspire.Hosting.* so all value-provider types are recognized.

Example fix

// before
.WithEnvironment("ENDPOINT", new MyCustomEndpointProvider(endpointResource));

// after
.WithEnvironment("ENDPOINT", endpointResource.GetEndpoint("https").Url);
Defensive patterns

Strategy: type-guard

Validate before calling

// Allow only documented reference/value types through to WithEnvironment/WithArgs.
if (value is not (string or FormattableString or IManifestExpressionProvider or IValueProvider or IAzureKeyVaultSecretReference))
    throw new NotSupportedException($"Unsupported container app value: {value.GetType()}");

Type guard

bool IsPublishableValue(object? v) => v is string or FormattableString or IManifestExpressionProvider or IAzureKeyVaultSecretReference;

Try / catch

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

Prevention

When it happens

Trigger: Passing a value of a type not handled by ProcessValue into WithEnvironment/WithArgs/WithEntrypoint/WithContainerRuntimeArgs on a container app resource during publish/generate, e.g., a custom IValueProvider implementation or an unsupported resource reference.

Common situations: Custom resource types emitting bespoke value providers; version mismatches where a newer reference type isn't handled by the installed Aspire.Hosting.Azure.AppContainers; typos like passing a builder instead of the underlying value.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

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

                }

                if (expr.StringFormats[index] is string format)
                {
                    val = BicepFormattingHelpers.FormatBicepExpression(val, format);
                }

                args[index++] = val;
            }

            return (FormattableStringFactory.Create(expr.Format, args), finalSecretType);
        }

        if (value is IManifestExpressionProvider manifestExpressionProvider)
        {
            return (AllocateParameter(manifestExpressionProvider, secretType), secretType);
        }

        throw new NotSupportedException("Unsupported value type " + value.GetType());
    }

    private BicepValue<string> AllocateKeyVaultSecretUriReference(IAzureKeyVaultSecretReference secretOutputReference)
    {
        var secret = secretOutputReference.AsKeyVaultSecret(Infra);

        return secret.Properties.SecretUri;
    }

    protected ProvisioningParameter AllocateContainerImageParameter()
        => AllocateParameter(new ContainerImageReference(resource));

    protected BicepValue<string> AllocateContainerPortParameter()
        => AllocateParameter(new ContainerPortReference(resource));

    protected static BicepValue<int> AsInt(BicepValue<string> value)
    {
        return new FunctionCallExpression(new IdentifierExpression("int"), value.Compile());

View on GitHub (pinned to 25830f84bd)