microsoft/aspire · error · ArgumentException
Must not be zero
Error message
Must not be zero
What it means
Thrown by Guard.ThrowIfZero in the vendored ConfluentKafka instrumentation's Guard helper when an int parameter equals zero, which the API treats as invalid. It throws ArgumentException with the parameter name and a default message of "Must not be zero". Typically used where zero is an ambiguous or meaningless value (e.g. an ID or count that must be positive).
Solutions
- Find the argument named in the exception and ensure a valid non-zero value is computed before the call.
- Treat a zero value as an early error in your own code: check and skip or throw a domain-specific exception.
- Investigate why the value was default(int) - often a failed lookup or uninitialized field rather than a legitimate 0.
Example fix
// before
int id = dict.GetValueOrDefault("id"); // 0 when missing
RegisterId(id);
// after
int id = dict.GetValueOrDefault("id");
if (id == 0)
{
throw new InvalidOperationException("id was not provided");
}
RegisterId(id); Defensive patterns
Strategy: validation
Validate before calling
if (value == 0)
{
throw new ArgumentException("Must not be zero", nameof(value));
} Try / catch
try
{
instrumented.SetCount(count);
}
catch (ArgumentException ex) when (ex.ParamName == "count")
{
logger.LogError(ex, "count must be non-zero");
} Prevention
- Treat default(int) as suspicious when it represents an ID or count
- Use nullable ints instead of 0 sentinels for missing values
- Check lookup results before using the resulting numeric value
When it happens
Trigger: Passing 0 for a guarded int argument such as an identifier, count, or quantity where a non-zero (usually positive) value is required.
Common situations: Uninitialized int fields defaulting to 0; ID lookups that returned default(int) when no record was found; counters or limits computed as zero from empty data.
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 be in the range
- Must not be null
- Must not be null or empty
- Must not be null or whitespace
- Cannot cast ' ' from ' ' to
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/5180e07af9c632ec.
Report an issue: GitHub.
Appendix: source
Thrown at src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs:116
{
throw new ArgumentException("Must not be null or whitespace", paramName);
}
}
#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("value")] string? paramName = null)
{
if (value == 0)
{
throw new ArgumentException(message, paramName);
}
}
/// <summary>
/// Throw an exception if the value is not considered a valid timeout.
/// </summary>
/// <param name="value">The value to check.</param>
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfInvalidTimeout(int value, [CallerArgumentExpression("value")] string? paramName = null)
{
ThrowIfOutOfRange(value, paramName, min: Timeout.Infinite, message: $"Must be non-negative or '{nameof(Timeout)}.{nameof(Timeout.Infinite)}'");
}
/// <summary>
/// Throw an exception if the value is not within the given range.
/// </summary>View on GitHub (pinned to 25830f84bd)