microsoft/aspire · error · ArgumentException
Must not be null or empty
Error message
Must not be null or empty
What it means
Thrown by Guard.ThrowIfNullOrEmpty in the vendored StackExchangeRedis instrumentation's Guard helper when a required string parameter is null or empty. On .NET targets it delegates to ArgumentException.ThrowIfNullOrEmpty; otherwise it throws ArgumentException with "Must not be null or empty". Guards required string values such as names or configuration strings.
Solutions
- Supply a valid non-empty value for the argument named in the exception.
- Fix the configuration source that yielded the empty string (missing key, blank entry).
- Validate with ArgumentException.ThrowIfNullOrEmpty at your own boundary for clearer diagnostics.
Example fix
// before var connStr = configuration["Redis:ConnectionString"]; // null UseConnectionString(connStr); // after var connStr = configuration["Redis:ConnectionString"]; ArgumentException.ThrowIfNullOrEmpty(connStr); UseConnectionString(connStr);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentException("Must not be null or empty", nameof(connectionString));
} Try / catch
try
{
AddRedisInstrumentation(o => o.ConnectionString = connectionString);
}
catch (ArgumentException ex) when (ex.ParamName == "connectionString")
{
logger.LogError(ex, "connection string missing from configuration");
} Prevention
- Validate required config keys at application startup
- Fail fast when an env var or config key is absent instead of defaulting to empty
- Log the config key path (not the secret) when validation fails
When it happens
Trigger: Passing null or "" to a guarded string parameter, e.g. an empty connection string, empty service name, or unset configuration key read from configuration that defaulted to empty.
Common situations: Missing environment variables defaulting to empty; connection strings defined but left blank in appsettings; string interpolation producing "" when an upstream value is missing.
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 whitespace
- Must not be null
- Must not be null or empty
- Must not be null or whitespace
- Error message cannot be null or empty.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/dbb13ea4a140936b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs:88
#endif
}
/// <summary>
/// Throw an exception if the value is null or empty.
/// </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 ThrowIfNullOrEmpty([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.ThrowIfNullOrEmpty(value, paramName);
#else
if (string.IsNullOrEmpty(value))
{
throw new ArgumentException("Must not be null or empty", paramName);
}
#endif
}
#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);
#elseView on GitHub (pinned to 25830f84bd)