microsoft/aspire · error · ArgumentException
Must not be null or whitespace
Error message
Must not be null or whitespace
What it means
Thrown by Guard.ThrowIfNullOrWhitespace in the vendored StackExchangeRedis instrumentation's Guard helper when a required string parameter is null, empty, or whitespace-only. On .NET targets it delegates to ArgumentException.ThrowIfNullOrWhiteSpace; otherwise it throws ArgumentException with "Must not be null or whitespace". Stricter than 2048: blank strings like " " also fail.
Solutions
- Trim and validate the value with string.IsNullOrWhiteSpace before passing it; provide a real value.
- Correct the upstream configuration or input source so the field cannot be blank.
- Add whitespace validation at your own boundary to fail with a more descriptive message.
Example fix
// before UseKey(settings["Key"] ?? " "); // after var key = settings["Key"]?.Trim(); ArgumentException.ThrowIfNullOrWhiteSpace(key); UseKey(key);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException("Must not be null or whitespace", nameof(name));
} Type guard
static bool IsValidName([NotNullWhen(true)] string? name) => !string.IsNullOrWhiteSpace(name);
Try / catch
try
{
instrumented.SetName(name);
}
catch (ArgumentException ex) when (ex.ParamName == "name")
{
logger.LogError(ex, "'name' is required and must not be blank");
} Prevention
- Trim inputs before validating required fields
- Add startup validation for all required string settings
- Reject blank placeholders in templates and config files early
When it happens
Trigger: Passing a null, empty, or whitespace-only string to any API guarded by ThrowIfNullOrWhitespace, e.g. a name, key, or identifier derived from config or user input that contained only spaces.
Common situations: Config entries with placeholder spaces; trim operations that emptied the string; templates where a required field was left as blank/whitespace filler.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Must not be null or empty
- Must not be null or whitespace
- Must not be null
- Must not be null or empty
- Error message cannot be null or empty.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/bdeecad419b7d5ff.
Report an issue: GitHub.
Appendix: source
Thrown at src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs:109
}
#pragma warning restore CS8777 // Parameter must have a non-null value when exiting.
/// <summary>
/// Throw an exception if the value is null or whitespace.
/// </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 ThrowIfNullOrWhitespace([NotNull] string? value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.
{
#if NET
ArgumentException.ThrowIfNullOrWhiteSpace(value, paramName);
#else
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Must not be null or whitespace", paramName);
}
#endif
}
#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);
#elseView on GitHub (pinned to 25830f84bd)