dotnet/orleans · error · ArgumentNullException
connection
Error message
connection
What it means
Thrown by EventHubOptions.ConfigureEventHubConnection(EventHubConnection, string) when the caller passes a null EventHubConnection instance. The library requires a live, already-constructed EventHubConnection to bind as the singleton connection factory. Note the null check executes after connection.EventHubName is dereferenced, so in practice a null argument will throw NullReferenceException on the prior line before reaching this guard.
Source
Thrown at src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubStreamOptions.cs:136
ValidateValues(eventHubName, consumerGroup);
if (credential is null)
{
throw new ArgumentNullException(nameof(credential));
}
CreateConnection = connectionOptions => new EventHubConnection(fullyQualifiedNamespace, EventHubName, credential, connectionOptions);
}
/// <summary>
/// Configures the Azure Event Hub connection using the provided connection instance.
/// </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))
{View on GitHub (pinned to fca799fa70)
Solutions
- Ensure the EventHubConnection instance is constructed (e.g. new EventHubConnection(fullyQualifiedNamespace, eventHubName, credential)) before calling ConfigureEventHubConnection.
- Register EventHubConnection in your DI container and resolve it before passing it in.
- If you cannot build the instance eagerly, use the delegate overload ConfigureEventHubConnection(CreateConnectionDelegate, string, string) instead.
Example fix
// before options.ConfigureEventHubConnection(existingConnection, consumerGroup); // existingConnection is null // after var connection = new EventHubConnection(fullyQualifiedNamespace, eventHubName, credential); options.ConfigureEventHubConnection(connection, consumerGroup);
Defensive patterns
Strategy: validation
Validate before calling
if (connection is null) throw new ArgumentNullException(nameof(connection)); options.ConfigureEventHubConnection(connection, consumerGroup);
Type guard
static bool IsValidConnection(EventHubConnection? c) => c is not null;
Prevention
- Construct EventHubConnection before the call, never pass unresolved nullable fields.
- Register EventHubConnection as a singleton in DI and resolve it explicitly.
When it happens
Trigger: Calling ConfigureEventHubConnection(null, consumerGroup) where the first argument is a null EventHubConnection reference.
Common situations: A DI container returns null for EventHubConnection because the registration is missing or fails; passing a not-yet-initialized field; refactoring that drops the assignment before the call.
Related errors
- createConnection
- credential
- Azure Event Hub connection not configured for stream provide
- EventHubOptions on stream provider {this.name} is invalid. E
- EventHubOptions on stream provider {this.name} is invalid. E
AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13).
Data as JSON: /api/errors/46ec987a4c3b8054.
Report an issue: GitHub.