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 ConfluentKafka instrumentation's Guard helper when a required string parameter is null, empty, or consists only of whitespace. It throws ArgumentException naming the parameter via CallerArgumentExpression. It is stricter than ThrowIfNullOrEmpty, rejecting strings like " " as well.

Solutions

  1. Trim the value and check string.IsNullOrWhiteSpace before passing it in; supply a real non-blank value.
  2. Fix the upstream source (config file, env var, user input) so the value cannot be blank.
  3. Add whitespace validation at your own boundary so it fails with a clearer message.

Example fix

// before
UseName(rawInput); // "   "

// after
var name = rawInput?.Trim();
ArgumentException.ThrowIfNullOrWhiteSpace(name);
UseName(name);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(value))
{
    throw new ArgumentException("Must not be null or whitespace", nameof(value));
}

Type guard

static bool IsMeaningful([NotNullWhen(true)] string? value) => !string.IsNullOrWhiteSpace(value);

Try / catch

try
{
    instrumented.Register(name);
}
catch (ArgumentException ex) when (ex.ParamName == "name")
{
    logger.LogError(ex, "'name' must not be blank");
}

Prevention

When it happens

Trigger: Passing a whitespace-only string to any API that routes through Guard.ThrowIfNullOrWhitespace, e.g. a name or key built from trimmed configuration that ended up as spaces.

Common situations: User-supplied input or YAML/JSON config values containing only spaces; values produced by string formatting that collapsed to whitespace; copy-pasted config entries with stray characters.

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


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/0b7c79a9a2a53870. Report an issue: GitHub.

Appendix: source

Thrown at src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs:99

            {
                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);
            }
        }
#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);
            }

View on GitHub (pinned to 25830f84bd)