SignalR/SignalR · error · ArgumentNullException

convert

Error message

convert

What it means

Thrown by the ObservableConnection<T> constructor when the 'convert' Func<string,T> is null. The observable converts each received JSON string to T before pushing it to observers, so the converter is mandatory.

Source

Thrown at src/Microsoft.AspNet.SignalR.Client/ObservableConnection.cs:26

namespace Microsoft.AspNet.SignalR.Client
{
#if !PORTABLE
    public class ObservableConnection<T> : IObservable<T>
    {
        private readonly Connection _connection;
        private readonly Func<string, T> _convert;

        public ObservableConnection(Connection connection, Func<string, T> convert)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

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

            _convert = convert;
            _connection = connection;
        }

        public IDisposable Subscribe(IObserver<T> observer)
        {
            Action<string> received = data =>
            {
                observer.OnNext(_convert(data));
            };

            Action closed = () =>
            {
                observer.OnCompleted();
            };

View on GitHub (pinned to 693053b89a)

Solutions

  1. Pass a non-null converter, e.g. 'data => JsonConvert.DeserializeObject<T>(data)'.
  2. For raw strings, pass the identity: 'data => data'.
  3. Null-check the converter at the call site if it comes from configuration.

Example fix

// before
var obs = new ObservableConnection<MyType>(connection, null);

// after
var obs = new ObservableConnection<MyType>(connection, data => JsonConvert.DeserializeObject<MyType>(data));
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

static bool IsValidConverter<T>(Func<string, T> f) => f != null;

Prevention

When it happens

Trigger: Constructing 'new ObservableConnection<T>(connection, null)'.

Common situations: Forgetting to supply a deserializer (e.g. JsonConvert.DeserializeObject<T>); refactoring that drops the lambda.

Related errors


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