{"record":{"id":"eb4ee4fb4f3a5ba1","repo":"dotnet/orleans","slug":"value-cannot-be-null-parameter-tokencredential","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'tokenCredential')","messagePattern":"Value cannot be null\\. \\(Parameter 'tokenCredential'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Azure/Shared/Storage/AzureStorageOperationOptions.cs","lineNumber":140,"sourceCode":"\n        internal void SetTableServiceClient(string connectionString)\n        {\n            if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentNullException(nameof(connectionString));\n            _tableServiceClient = null;\n            CreateClient = () => Task.FromResult(new TableServiceClient(connectionString, GetTableClientOptions()));\n        }\n\n        internal void SetTableServiceClient(Uri serviceUri)\n        {\n            if (serviceUri is null) throw new ArgumentNullException(nameof(serviceUri));\n            _tableServiceClient = null;\n            CreateClient = () => Task.FromResult(new TableServiceClient(serviceUri, GetTableClientOptions()));\n        }\n\n        internal void SetTableServiceClient(Uri serviceUri, TokenCredential tokenCredential)\n        {\n            if (serviceUri is null) throw new ArgumentNullException(nameof(serviceUri));\n            if (tokenCredential is null) throw new ArgumentNullException(nameof(tokenCredential));\n            _tableServiceClient = null;\n            CreateClient = () => Task.FromResult(new TableServiceClient(serviceUri, tokenCredential, GetTableClientOptions()));\n        }\n\n        internal void SetTableServiceClient(Uri serviceUri, AzureSasCredential azureSasCredential)\n        {\n            if (serviceUri is null) throw new ArgumentNullException(nameof(serviceUri));\n            if (azureSasCredential is null) throw new ArgumentNullException(nameof(azureSasCredential));\n            _tableServiceClient = null;\n            CreateClient = () => Task.FromResult(new TableServiceClient(serviceUri, azureSasCredential, GetTableClientOptions()));\n        }\n\n        internal void SetTableServiceClient(Uri serviceUri, TableSharedKeyCredential sharedKeyCredential)\n        {\n            if (serviceUri is null) throw new ArgumentNullException(nameof(serviceUri));\n            if (sharedKeyCredential is null) throw new ArgumentNullException(nameof(sharedKeyCredential));\n            _tableServiceClient = null;\n            CreateClient = () => Task.FromResult(new TableServiceClient(serviceUri, sharedKeyCredential, GetTableClientOptions()));","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/Azure/Shared/Storage/AzureStorageOperationOptions.cs#L122-L158","documentation":"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.","triggerScenarios":"Calling ConfigureTableServiceClient(uri, credential) with a valid uri but a null credential — typically the credential object failed to construct.","commonSituations":"DefaultAzureCredential/ClientSecretCredential not instantiated because config values (tenant, client id, secret) were missing; DI not resolving the credential; conditional credential creation returning null.","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."],"exampleFix":"// before\noptions.ConfigureTableServiceClient(uri, credential); // credential null\n// after\nTokenCredential cred = new DefaultAzureCredential(new DefaultAzureCredentialOptions { ... });\noptions.TableServiceClient = new TableServiceClient(uri, cred);","handlingStrategy":"validation","validationCode":"TokenCredential cred = new DefaultAzureCredential();\noptions.TableServiceClient = new TableServiceClient(serviceUri, cred);","typeGuard":"static bool HasCredential(TokenCredential? c) => c is not null;","tryCatchPattern":"catch (ArgumentNullException ex) when (ex.ParamName == \"tokenCredential\") { /* construct a concrete TokenCredential first */ }","preventionTips":["Resolve TokenCredential through DI.","Validate identity config (tenant/client id) before constructing the credential."],"tags":["orleans","azure-storage","azure-table","configuration","aad","argument"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}