microsoft/aspire · error · ArgumentNullException

Must not be null

Error message

Must not be null

What it means

Thrown by Guard.ThrowIfNull in the vendored StackExchangeRedis instrumentation's Guard helper when a required object parameter is null. On NET6+ targets it delegates to ArgumentNullException.ThrowIfNull (standard SDK message); on older targets it throws ArgumentNullException with the message "Must not be null". Same contract as 2040 but from the Redis instrumentation.

Solutions

  1. Check paramName and ensure the referenced argument is initialized before the call.
  2. Verify the Redis connection is successfully created and non-null before passing it to the instrumentation.
  3. Enable nullable reference types to catch the null flow at compile time.

Example fix

// before
IConnectionMultiplexer? mux = TryConnect(); // may be null
AddRedisInstrumentation(mux);

// after
IConnectionMultiplexer mux = TryConnect() ?? throw new InvalidOperationException("could not connect to Redis");
AddRedisInstrumentation(mux);
Defensive patterns

Strategy: validation

Validate before calling

if (multiplexer is null)
{
    throw new ArgumentNullException(nameof(multiplexer));
}

Type guard

static bool HasMultiplexer([NotNullWhen(true)] IConnectionMultiplexer? mux) => mux is not null;

Try / catch

try
{
    AddRedisInstrumentation(multiplexer);
}
catch (ArgumentNullException ex) when (ex.ParamName == "multiplexer")
{
    logger.LogError(ex, "Redis multiplexer was null; connection likely failed");
}

Prevention

When it happens

Trigger: Calling a StackExchangeRedis instrumentation API (or code it guards) with null for a required parameter, e.g. null IConnectionMultiplexer, null options, or null configuration instance.

Common situations: Multiplexer initialization failed or was not awaited before registering the instrumentation; DI returning null for an optional dependency; config object not constructed before use.

Related errors


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

Appendix: source

Thrown at src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs:68

    /// Methods for guarding against exception throwing values.
    /// </summary>
    internal static class Guard
    {
        /// <summary>
        /// Throw an exception if the value is null.
        /// </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 ThrowIfNull([NotNull] object? value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
        {
#if NET
            ArgumentNullException.ThrowIfNull(value, paramName);
#else
            if (value is null)
            {
                throw new ArgumentNullException(paramName, "Must not be null");
            }
#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))

View on GitHub (pinned to 25830f84bd)