dotnet/orleans · error · ArgumentNullException

Value cannot be null. (Parameter 'sharedKeyCredential')

Error message

Value cannot be null. (Parameter 'sharedKeyCredential')

What it means

Thrown by AzureStorageOperationOptions.SetTableServiceClient(Uri, TableSharedKeyCredential) when the TableSharedKeyCredential is null. The shared-key credential carries the account name and key; without it the SDK cannot sign requests.

Source

Thrown at src/Azure/Shared/Storage/AzureStorageOperationOptions.cs:156

        {
            if (serviceUri is null) throw new ArgumentNullException(nameof(serviceUri));
            if (tokenCredential is null) throw new ArgumentNullException(nameof(tokenCredential));
            _tableServiceClient = null;
            CreateClient = () => Task.FromResult(new TableServiceClient(serviceUri, tokenCredential, GetTableClientOptions()));
        }

        internal void SetTableServiceClient(Uri serviceUri, AzureSasCredential azureSasCredential)
        {
            if (serviceUri is null) throw new ArgumentNullException(nameof(serviceUri));
            if (azureSasCredential is null) throw new ArgumentNullException(nameof(azureSasCredential));
            _tableServiceClient = null;
            CreateClient = () => Task.FromResult(new TableServiceClient(serviceUri, azureSasCredential, GetTableClientOptions()));
        }

        internal void SetTableServiceClient(Uri serviceUri, TableSharedKeyCredential sharedKeyCredential)
        {
            if (serviceUri is null) throw new ArgumentNullException(nameof(serviceUri));
            if (sharedKeyCredential is null) throw new ArgumentNullException(nameof(sharedKeyCredential));
            _tableServiceClient = null;
            CreateClient = () => Task.FromResult(new TableServiceClient(serviceUri, sharedKeyCredential, GetTableClientOptions()));
        }

        internal TableClientOptions GetTableClientOptions()
        {
            var clientOptions = ClientOptions ??= new TableClientOptions();
            ConfigureRetryOptions(clientOptions.Retry, StoragePolicyOptions);
            return clientOptions;
        }

        private static void ConfigureRetryOptions(RetryOptions retryOptions, AzureStoragePolicyOptions storagePolicyOptions)
        {
            // Keep this aligned with AzureStoragePolicyOptions defaults, which mirror Azure Storage SDK retry settings.
            var delay = storagePolicyOptions.PauseBetweenOperationRetries > TimeSpan.Zero
                ? storagePolicyOptions.PauseBetweenOperationRetries
                : TimeSpan.FromSeconds(0.8);

View on GitHub (pinned to fca799fa70)

Solutions

  1. Construct a non-null TableSharedKeyCredential from the account name and key, or set TableServiceClient directly.
  2. Load the key from the secret store and validate presence.
  3. Prefer constructing the client yourself.

Example fix

// before
options.ConfigureTableServiceClient(uri, sharedKeyCred); // sharedKeyCred null
// after
var name = config["AccountName"] ?? throw new InvalidOperationException("Missing AccountName");
var key  = secrets["AccountKey"]  ?? throw new InvalidOperationException("Missing AccountKey");
options.TableServiceClient = new TableServiceClient(uri, new TableSharedKeyCredential(name, key));
Defensive patterns

Strategy: validation

Validate before calling

var name = config["AccountName"] ?? throw new InvalidOperationException("Missing AccountName");
var key  = secrets["AccountKey"]  ?? throw new InvalidOperationException("Missing AccountKey");
options.TableServiceClient = new TableServiceClient(serviceUri, new TableSharedKeyCredential(name, key));

Type guard

static bool HasSharedKey(TableSharedKeyCredential? c) => c is not null;

Try / catch

catch (ArgumentNullException ex) when (ex.ParamName == "sharedKeyCredential") { /* load account name/key from secrets */ }

Prevention

When it happens

Trigger: Calling ConfigureTableServiceClient(uri, sharedKey) with a valid uri but a null TableSharedKeyCredential — usually the account key was not loaded.

Common situations: Account key missing from secrets; key rotation code path producing null; misnamed config key for the storage account name/key.

Related errors


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