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
- Pass the same IHttpClient the transport holds (DefaultHttpClient or an injected non-null mock).
- Prefer ClientTransportBase.Negotiate(...) which forwards its own HttpClient to the helper.
- 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
- Pass the transport's HttpClient to negotiation helpers; do not stub with null.
- Use ClientTransportBase.Negotiate(...) which forwards its own HttpClient.
- Ensure DI/test mocks return a non-null IHttpClient.
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.