microsoft/aspire · error · ArgumentException
Expected a string, integer, or
Error message
Expected a string, integer, or {nameof(BicepValueProxy)}. What it means
BicepValueFactory.ToExpression converts an indexer's value into a Bicep expression. It supports only string literals, int literals, and BicepValueProxy instances; anything else throws ArgumentException naming the offending parameter. This enforces that only Bicep-expressible primitives flow into generated expressions.
Solutions
- Convert the value to string or int before indexing (e.g. myLong.ToString(), ((int)myEnum).ToString()).
- Wrap complex values via BicepValueProxy/expression helpers instead of raw objects.
- If it's an int-like value, ensure it's genuinely int not long (explicit cast).
- Check the call site against the accepted set: string, int, BicepValueProxy.
Example fix
// before
var value = factory.Index(config.GetSection("replicas").Get<long>()); // long
// after
var value = factory.Index(((int)config.GetValue<long>("replicas")).ToString()); Defensive patterns
Strategy: type-guard
Validate before calling
bool supported = value is string or int or BicepValueProxy;
Type guard
bool IsBicepIndexable(object? v) => v is string or int or BicepValueProxy;
Try / catch
try { expr = factory.Index(raw); }
catch (ArgumentException ex) when (ex.ParamName == "value") { /* convert raw to string/int and retry */ } Prevention
- Convert longs, bools, enums, and Guids to string or int before using them as Bicep index values.
- At config boundaries, parse values into the supported primitive types.
- Keep a small helper that normalizes config values to string/int before Bicep APIs.
When it happens
Trigger: Using the BicepValueProxy Index API with a value of an unsupported type — e.g. long, double, bool, Guid, DateTime, or an enum — as an index/key/argument instead of a string, int, or proxy.
Common situations: Passing a bool or enum from host code into an indexer; using a long from a config value; passing a Guid as a resource key; conversion from JSON config delivering nested objects.
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
- A of type cannot be assigned to a BicepValue< >.
- Expected a literal or .
- An Azure principal parameter was not supplied a value…
- Azure resource ' ' is missing required output ' '. Ensure…
- AzureEnvironmentResource must be present in the application…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/961a42574ce660b8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Provisioning/BicepValueFactory.cs:507
return new();
}
#pragma warning restore CA1822
private static BicepValueProxy FromExpression(BicepExpression expression, bool isSecure)
{
return BicepValueProxy.CreateExpression(expression, isSecure);
}
private static BicepExpression ToExpression(object value)
{
ArgumentNullException.ThrowIfNull(value);
return value switch
{
string literal => literal,
int literal => literal,
BicepValueProxy proxy => proxy.ToBicepExpression(),
_ => throw new ArgumentException($"Expected a string, integer, or {nameof(BicepValueProxy)}.", nameof(value))
};
}
private static bool IsSecure(object value)
{
return value is BicepValueProxy proxy && proxy.IsSecure;
}
}
View on GitHub (pinned to 25830f84bd)