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 ConfluentKafka instrumentation's Guard helper when a required string parameter is null or the empty string. It wraps ArgumentException with the offending parameter name and asserts the value is non-null on exit. It guards required string configuration such as names, keys, or identifiers.
Solutions
- Read paramName from the ArgumentException and supply a non-empty value for that argument before the call.
- Validate string inputs with Guard.ThrowIfNullOrEmpty or ArgumentException.ThrowIfNullOrEmpty at your own boundary.
- Trace back the string to its source (config/env var) and fix the empty value there.
Example fix
// before var bootstrap = configuration["Kafka:BootstrapServers"]; // "" UseBootstrapServers(bootstrap); // after var bootstrap = configuration["Kafka:BootstrapServers"]; ArgumentException.ThrowIfNullOrEmpty(bootstrap); UseBootstrapServers(bootstrap);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(value))
{
throw new ArgumentException("Must not be null or empty", nameof(value));
} Try / catch
try
{
instrumented.Configure(name);
}
catch (ArgumentException ex) when (ex.ParamName == "name")
{
logger.LogError(ex, "'name' must be a non-empty string");
} Prevention
- Validate strings read from configuration before use
- Never default string config values to ""; use meaningful defaults or fail fast
- Run configuration binding validation at startup
When it happens
Trigger: Calling a guarded API with a required string argument set to null or "", e.g. an empty bootstrap servers string, empty operation/topic name, or unset configuration value passed straight through.
Common situations: Connection strings or bootstrap servers read from configuration that resolved to an empty string; missing environment variables whose defaults are empty; string fields initialized to "" instead of real values.
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 be in the range
- Must not be null
- Must not be null or empty
- Must not be null or whitespace
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/0996d49d91fd33cc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs:82
if (value is null)
{
throw new ArgumentNullException(paramName, "Must not be null");
}
}
/// <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("value")] string? paramName = null)
#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentException("Must not be null or empty", paramName);
}
}
#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("value")] string? paramName = null)
#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Must not be null or whitespace", paramName);
}View on GitHub (pinned to 25830f84bd)