dotnet/orleans · error · ArgumentNullException

credential

Error message

credential

What it means

EventHubOptions.ConfigureEventHubConnection(fullyQualifiedNamespace, eventHubName, consumerGroup, AzureNamedKeyCredential) throws ArgumentNullException when the credential argument is null. The AzureNamedKeyCredential carries the shared access key name and key used to authenticate to Event Hub. Without a valid credential, EventHubConnection cannot authenticate, so Orleans fails fast at configuration time rather than at first connection attempt.

Source

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

        /// <summary>
        /// Configures the Azure Event Hub connection using the provided fully-qualified namespace string and credential.
        /// </summary>
        public void ConfigureEventHubConnection(string fullyQualifiedNamespace, string eventHubName, string consumerGroup, AzureNamedKeyCredential credential)
        {
            EventHubName = eventHubName;
            ConsumerGroup = consumerGroup;

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

            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 fully-qualified namespace string and credential.
        /// </summary>
        public void ConfigureEventHubConnection(string fullyQualifiedNamespace, string eventHubName, string consumerGroup, AzureSasCredential credential)
        {
            EventHubName = eventHubName;
            ConsumerGroup = consumerGroup;

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

View on GitHub (pinned to fca799fa70)

Solutions

  1. Construct a valid AzureNamedKeyCredential from your shared access key name and key before calling ConfigureEventHubConnection.
  2. Verify both the key name and key value are present in configuration.
  3. If the credential is resolved from DI, ensure it is registered as a singleton and not returning null.

Example fix

// before — credential is null because key config is missing
AzureNamedKeyCredential credential = null;
if (config["SharedAccessKeyName"] != null)
    credential = new AzureNamedKeyCredential(config["SharedAccessKeyName"], config["SharedAccessKey"]);
options.ConfigureEventHubConnection(ns, "myhub", "$Default", credential);

// after — always construct a valid credential
var keyName = config["SharedAccessKeyName"]
    ?? throw new InvalidOperationException("SharedAccessKeyName not configured.");
var key = config["SharedAccessKey"]
    ?? throw new InvalidOperationException("SharedAccessKey not configured.");
var credential = new AzureNamedKeyCredential(keyName, key);
options.ConfigureEventHubConnection(ns, "myhub", "$Default", credential);
Defensive patterns

Strategy: validation

Validate before calling

// Ensure credential is non-null before configuring:
var keyName = config["EventHub:SharedAccessKeyName"]
    ?? throw new InvalidOperationException("SharedAccessKeyName is not configured.");
var key = config["EventHub:SharedAccessKey"]
    ?? throw new InvalidOperationException("SharedAccessKey is not configured.");

var credential = new AzureNamedKeyCredential(keyName, key);
options.ConfigureEventHubConnection(fullyQualifiedNamespace, eventHubName, consumerGroup, credential);

Type guard

static bool IsValidCredential(AzureNamedKeyCredential? credential)
    => credential is not null;

Prevention

When it happens

Trigger: Calling the AzureNamedKeyCredential overload with credential set to null. This happens when the AzureNamedKeyCredential is constructed from configuration (key name and key) and one of the components is missing, resulting in a null credential object being passed.

Common situations: The shared access key is missing from configuration and the credential construction was skipped or returned null; a factory method that creates the credential returns null on missing config; a DI registration for AzureNamedKeyCredential is not properly resolved; a migration from connection strings to credentials where the credential creation step was omitted.

Related errors


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