MassTransit/MassTransit · error · ArgumentNullException

Value cannot be null. (Parameter 'values')

Error message

Value cannot be null. (Parameter 'values')

What it means

RequestClient.Create(object values) throws ArgumentNullException when the message values object used to initialize the request is null. The client needs a non-null message (or anonymous object) to build and send the request.

Solutions

  1. Ensure the message object is constructed before calling Create
  2. Null-check/guard the message in the caller
  3. Use the typed Create(TRequest message) overload with an initialized message instance

Example fix

// before
var handle = _client.Create(order ?? null);
// after
if (order == null) throw new InvalidOperationException("order required");
var handle = _client.Create(order);
Defensive patterns

Strategy: validation

Validate before calling

if (values is null) throw new InvalidOperationException("request message required");

Type guard

bool HasMessage(object? v) => v is not null;

Try / catch

try { var h = client.Create(values); } catch (ArgumentNullException ex) { logger.LogError(ex, "null request values"); throw; }

Prevention

When it happens

Trigger: Calling Create(null) on an IRequestClient<TRequest> — often when the message object is the result of a failed mapping or an uninitialized variable.

Common situations: Passing a deserialized message that came back null; building the request from optional data that was never populated.

Related errors


AI-assisted analysis of MassTransit/MassTransit@62ab339afa (2026-09-13). Data as JSON: /api/errors/22719fb9bd37ae37. Report an issue: GitHub.

Appendix: source

Thrown at src/MassTransit/Clients/RequestClient.cs:38

            _timeout = timeout;
        }

        public RequestHandle<TRequest> Create(TRequest message, CancellationToken cancellationToken, RequestTimeout timeout)
        {
            async Task<TRequest> Request(Guid requestId, IPipe<SendContext<TRequest>> pipe, CancellationToken token)
            {
                await _requestSendEndpoint.Send(requestId, message, pipe, token).ConfigureAwait(false);

                return message;
            }

            return new ClientRequestHandle<TRequest>(_context, Request, cancellationToken, timeout.Or(_timeout));
        }

        public RequestHandle<TRequest> Create(object values, CancellationToken cancellationToken = default, RequestTimeout timeout = default)
        {
            if (values == null)
                throw new ArgumentNullException(nameof(values));

            async Task<TRequest> Request(Guid requestId, IPipe<SendContext<TRequest>> pipe, CancellationToken token)
            {
                return await _requestSendEndpoint.Send(requestId, values, pipe, token).ConfigureAwait(false);
            }

            return new ClientRequestHandle<TRequest>(_context, Request, cancellationToken, timeout.Or(_timeout));
        }

        public Task<Response<T>> GetResponse<T>(TRequest message, CancellationToken cancellationToken, RequestTimeout timeout)
            where T : class
        {
            return GetResponse<T>(message, null, cancellationToken, timeout);
        }

        public Task<Response<T>> GetResponse<T>(TRequest message, RequestPipeConfiguratorCallback<TRequest> callback,
            CancellationToken cancellationToken = default, RequestTimeout timeout = default)
            where T : class

View on GitHub (pinned to 62ab339afa)