dotnet/orleans · error · ArgumentNullException
Value cannot be null. (Parameter 'tokenCredential')
Error message
Value cannot be null. (Parameter 'tokenCredential')
What it means
Thrown by AzureStorageOperationOptions.SetTableServiceClient(Uri, TokenCredential) when the TokenCredential argument is null. Without a credential the SDK cannot authenticate, so the guard rejects it before building the client factory.
Source
Thrown at src/Azure/Shared/Storage/AzureStorageOperationOptions.cs:140
internal void SetTableServiceClient(string connectionString)
{
if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentNullException(nameof(connectionString));
_tableServiceClient = null;
CreateClient = () => Task.FromResult(new TableServiceClient(connectionString, GetTableClientOptions()));
}
internal void SetTableServiceClient(Uri serviceUri)
{
if (serviceUri is null) throw new ArgumentNullException(nameof(serviceUri));
_tableServiceClient = null;
CreateClient = () => Task.FromResult(new TableServiceClient(serviceUri, GetTableClientOptions()));
}
internal void SetTableServiceClient(Uri serviceUri, TokenCredential tokenCredential)
{
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()));View on GitHub (pinned to fca799fa70)
Solutions
- Construct a concrete TokenCredential (DefaultAzureCredential, ClientSecretCredential, etc.) and pass it non-null, or set TableServiceClient directly.
- Resolve credentials through DI so they are never null at the call site.
- Validate required identity config (tenantId/clientId/secret) before building the credential.
Example fix
// before
options.ConfigureTableServiceClient(uri, credential); // credential null
// after
TokenCredential cred = new DefaultAzureCredential(new DefaultAzureCredentialOptions { ... });
options.TableServiceClient = new TableServiceClient(uri, cred); Defensive patterns
Strategy: validation
Validate before calling
TokenCredential cred = new DefaultAzureCredential(); options.TableServiceClient = new TableServiceClient(serviceUri, cred);
Type guard
static bool HasCredential(TokenCredential? c) => c is not null;
Try / catch
catch (ArgumentNullException ex) when (ex.ParamName == "tokenCredential") { /* construct a concrete TokenCredential first */ } Prevention
- Resolve TokenCredential through DI.
- Validate identity config (tenant/client id) before constructing the credential.
When it happens
Trigger: Calling ConfigureTableServiceClient(uri, credential) with a valid uri but a null credential — typically the credential object failed to construct.
Common situations: DefaultAzureCredential/ClientSecretCredential not instantiated because config values (tenant, client id, secret) were missing; DI not resolving the credential; conditional credential creation returning null.
Related errors
- Value cannot be null. (Parameter 'createClientCallback')
- Value cannot be null. (Parameter 'connectionString')
- Value cannot be null. (Parameter 'serviceUri')
- Value cannot be null. (Parameter 'azureSasCredential')
- Value cannot be null. (Parameter 'sharedKeyCredential')
AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13).
Data as JSON: /api/errors/eb4ee4fb4f3a5ba1.
Report an issue: GitHub.