dotnet/orleans · error · ArgumentNullException

createConnection

Error message

createConnection

What it means

Thrown by the delegate overload of ConfigureEventHubConnection when the supplied CreateConnectionDelegate is null. The library stores the delegate as the connection factory and cannot operate without one.

Source

Thrown at src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubStreamOptions.cs:148

        /// </summary>
        public void ConfigureEventHubConnection(EventHubConnection connection, string consumerGroup)
        {
            EventHubName = connection.EventHubName;
            ConsumerGroup = consumerGroup;
            ValidateValues(connection.EventHubName, consumerGroup);
            if (connection is null) throw new ArgumentNullException(nameof(connection));
            CreateConnection = _ => connection;
        }

        /// <summary>
        /// Configures the Azure Event Hub connection using the provided delegate.
        /// </summary>
        public void ConfigureEventHubConnection(CreateConnectionDelegate createConnection, string eventHubName, string consumerGroup)
        {
            EventHubName = eventHubName;
            ConsumerGroup = consumerGroup;
            ValidateValues(eventHubName, consumerGroup);
            CreateConnection = createConnection ?? throw new ArgumentNullException(nameof(createConnection));
        }

        private static void ValidateValues(string eventHubName, string consumerGroup)
        {
            if (string.IsNullOrWhiteSpace(eventHubName))
            {
                throw new ArgumentException("A non-null, non-empty value must be provided.", nameof(eventHubName));
            }

            if (string.IsNullOrWhiteSpace(consumerGroup))
            {
                throw new ArgumentException("A non-null, non-empty value must be provided.", nameof(consumerGroup));
            }
        }
    }

    public class EventHubOptionsValidator : IConfigurationValidator
    {

View on GitHub (pinned to fca799fa70)

Solutions

  1. Provide a non-null CreateConnectionDelegate, e.g. new CreateConnectionDelegate(opts => new EventHubConnection(ns, hub, cred, opts)).
  2. If resolving from DI, fall back to one of the other ConfigureEventHubConnection overloads (connection instance or endpoint+token) rather than passing null.
  3. Guard the call site: if (factory is not null) options.ConfigureEventHubConnection(factory, hub, group);

Example fix

// before
options.ConfigureEventHubConnection(null, eventHubName, consumerGroup);

// after
var factory = new CreateConnectionDelegate(
    opts => new EventHubConnection(fqdn, eventHubName, credential, opts));
options.ConfigureEventHubConnection(factory, eventHubName, consumerGroup);
Defensive patterns

Strategy: validation

Validate before calling

if (createConnection is null) throw new ArgumentNullException(nameof(createConnection));
options.ConfigureEventHubConnection(createConnection, eventHubName, consumerGroup);

Type guard

static bool IsValidFactory(CreateConnectionDelegate? d) => d is not null;

Prevention

When it happens

Trigger: Calling ConfigureEventHubConnection(null, eventHubName, consumerGroup), or passing a factory field/property that was never assigned.

Common situations: A conditional assignment that leaves the delegate null on a cold path; copy-paste from a sample that omits the factory; refactor that resolves the delegate from a nullable DI service.

Related errors


AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13). Data as JSON: /api/errors/ed0696f8399126af. Report an issue: GitHub.