microsoft/aspire · error · ArgumentNullException

Must not be null

Error message

Must not be null

What it means

This is an ArgumentNullException thrown by Guard.ThrowIfNull in the vendored OpenTelemetry Kafka instrumentation's shared Guard helper. It fires whenever a caller passes null to a public API parameter that the library requires to be non-null, using CallerArgumentExpression to name the offending parameter. It is a programming/contract error, not a runtime environmental failure.

Solutions

  1. Inspect the paramName in the ArgumentNullException and initialize/assign the referenced argument before the call.
  2. Add Guard.ThrowIfNull (or ArgumentNullException.ThrowIfNull) at your own boundary to fail fast at the point of the bug.
  3. Check nullable-reference-type warnings at the call site; enabling <Nullable>enable</Nullable> surfaces the null flow at compile time.

Example fix

// before
AddConsumer(consumer: null);

// after
var consumer = consumerBuilder.Build();
AddConsumer(consumer);
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

static bool IsNotNull<T>([NotNullWhen(true)] T? value) where T : class => value is not null;

Try / catch

try
{
    instrumented.Call(requiredArg);
}
catch (ArgumentNullException ex) when (ex.ParamName == "requiredArg")
{
    logger.LogError(ex, "requiredArg was null");
}

Prevention

When it happens

Trigger: Any call into the ConfluentKafka instrumentation (or code paths it guards) passing null for a required object parameter, e.g. a null consumer/producer, null configuration, or null callback argument that is forwarded to Guard.ThrowIfNull.

Common situations: Constructing tracing options with an unset consumer/producer reference; passing null delegates or state objects; refactoring that removed an initialization step so a field is still null when handed to the instrumentation.

Related errors


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

Appendix: source

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

namespace OpenTelemetry.Internal
{
    /// <summary>
    /// 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("value")] string? paramName = null)
        {
            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);
            }
        }

View on GitHub (pinned to 25830f84bd)