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
- 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.
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
- Pass strings, FormattableStrings, or resource reference APIs into WithEnvironment/WithArgs.
- Avoid custom IValueProvider implementations for container apps.
- Keep Aspire.Hosting.* packages on matching versions.
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
- Unsupported value type
- A of type cannot be assigned to a BicepValue< >.
- Expected a string, integer, or
- Expected a literal or .
- The property ' ' is not supported for the endpoint ' '.
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)