SignalR/SignalR · error · ArgumentNullException

httpClient

Error message

httpClient

What it means

Thrown by TransportHelper.GetNegotiationResponse when 'httpClient' is null. Negotiation issues an HTTP GET to the /negotiate endpoint and needs the IHttpClient to perform it.

Source

Thrown at src/Microsoft.AspNet.SignalR.Client/Transports/TransportHelper.cs:21

using System;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR.Client.Http;
using Microsoft.AspNet.SignalR.Client.Infrastructure;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.AspNet.SignalR.Client.Transports
{
    public class TransportHelper
    {
        // virtual to allow mocking
        public virtual Task<NegotiationResponse> GetNegotiationResponse(IHttpClient httpClient, IConnection connection, string connectionData)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException("httpClient");
            }

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            var negotiateUrl = UrlBuilder.BuildNegotiate(connection, connectionData);

            httpClient.Initialize(connection);

            return httpClient.Get(negotiateUrl, connection.PrepareRequest, isLongRunning: false)
                            .Then(response => response.ReadAsString())
                            .Then(raw =>
                            {
                                if (String.IsNullOrEmpty(raw))
                                {
                                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_ServerNegotiationFailed));

View on GitHub (pinned to 693053b89a)

Solutions

  1. Pass the same IHttpClient the transport holds (DefaultHttpClient or an injected non-null mock).
  2. Prefer ClientTransportBase.Negotiate(...) which forwards its own HttpClient to the helper.
  3. Null-check httpClient at the orchestration layer before delegating.

Example fix

// before
_transportHelper.GetNegotiationResponse(null, connection, connectionData);

// after
_transportHelper.GetNegotiationResponse(httpClient, connection, connectionData);
Defensive patterns

Strategy: validation

Validate before calling

if (httpClient == null) throw new ArgumentNullException(nameof(httpClient));

Type guard

static bool HasHttpClient(IHttpClient c) => c != null;

Prevention

When it happens

Trigger: Calling GetNegotiationResponse(null, connection, connectionData) — usually from a custom transport or test stubbing TransportHelper.

Common situations: Mocking TransportHelper / GetNegotiationResponse in tests and passing null; DI misconfiguration of the HttpClient dependency.

Related errors


AI-assisted analysis of SignalR/SignalR@693053b89a (2026-08-13). Data as JSON: /api/errors/289abd753c72f0ad. Report an issue: GitHub.