microsoft/aspire · error · ArgumentException
Must not be zero
Error message
Must not be zero
What it means
Guard.ThrowIfZero validates that an argument is not exactly zero, throwing ArgumentException with 'Must not be zero' when it is. It's a vendored guard utility used by the StackExchangeRedis instrumentation to fail fast on nonsensical zero values (e.g. zero-length buffers or zero-capacity settings). On .NET 6+ it delegates to ArgumentOutOfRangeException.ThrowIfZero, which throws ArgumentOutOfRangeException instead.
Solutions
- Inspect the argument named in the exception and ensure a non-zero value is provided before the call.
- Fix the upstream default or initializer so the value is populated with a meaningful value.
- Validate the value yourself before calling and short-circuit with a clearer error.
- If zero is legitimately allowed at your call site, remove the ThrowIfZero check or handle it before invoking.
Example fix
// before
Guard.ThrowIfZero(port, nameof(port)); // port defaults to 0
// after
if (port == 0) { port = 6379; }
Guard.ThrowIfZero(port, nameof(port)); Defensive patterns
Strategy: validation
Validate before calling
if (value == 0) throw new ArgumentException("value must be non-zero", nameof(value)); Try / catch
catch (ArgumentException ex) when (ex.ParamName == paramName) { /* supply fallback or report config error */ } Prevention
- Initialize numeric settings with non-zero defaults.
- Validate config at startup before constructing instrumentation.
- Never pass raw parsed values without checking for 0/empty.
When it happens
Trigger: Calling Guard.ThrowIfZero(value) with value == 0; typically via instrumented paths that validate numeric parameters (counts, sizes, ports) before use.
Common situations: Passing a variable that defaulted to 0 instead of a real value; forgetting to initialize a size/capacity field; parsing config that yielded 0 when unset.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Must not be negative
- Address prefix must be a string or a parameter resource…
- Address prefix must be omitted, a string, or a parameter…
- All resources should be of the same kind when calling…
- apiPath is required when apiTarget is specified.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/836ebe2c5e4f0702.
Report an issue: GitHub.
Appendix: source
Thrown at src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs:130
}
#pragma warning restore CS8777 // Parameter must have a non-null value when exiting.
/// <summary>
/// Throw an exception if the value is zero.
/// </summary>
/// <param name="value">The value to check.</param>
/// <param name="message">The message to use in the thrown exception.</param>
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfZero(int value, string message = "Must not be zero", [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
#if NET
ArgumentOutOfRangeException.ThrowIfZero(value, paramName);
#else
if (value == 0)
{
throw new ArgumentException(message, paramName);
}
#endif
}
/// <summary>
/// Throw an exception if the value is negative.
/// </summary>
/// <param name="value">The value to check.</param>
/// <param name="message">The message to use in the thrown exception.</param>
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNegative(int value, string message = "Must not be negative", [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(paramName, message);
}View on GitHub (pinned to 25830f84bd)