{"record":{"id":"a2491e4f83877b12","repo":"dotnet/orleans","slug":"the-configured-azure-table-service-client-factory","errorCode":null,"errorMessage":"The configured Azure Table service client factory returned null.","messagePattern":"The configured Azure Table service client factory returned null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Azure/Orleans.Journaling.AzureStorage/AzureTableJournalStorageProvider.cs","lineNumber":43,"sourceCode":"        _options = options.Value;\n        var journalFormatKey = ValidateJournalFormatKey(managerOptions.Value.JournalFormatKey);\n        ValidateJournalFormat(serviceProvider, journalFormatKey);\n        _shared = new AzureTableJournalStorage.AzureTableJournalStorageShared(\n            logger,\n            options,\n            _tableClientProvider,\n            instruments ?? AzureTableJournalStorageInstruments.CreateForDirectConstruction(),\n            journalFormatKey);\n    }\n\n    private async Task Initialize(CancellationToken cancellationToken)\n    {\n        var createClient = _options.CreateClient\n            ?? throw new InvalidOperationException(\n                $\"No Azure Table service client was configured. Set {nameof(AzureTableJournalStorageOptions.TableServiceClient)} \" +\n                $\"or call {nameof(AzureTableJournalStorageOptions.ConfigureTableServiceClient)}.\");\n        var client = await createClient(cancellationToken).ConfigureAwait(false)\n            ?? throw new InvalidOperationException(\"The configured Azure Table service client factory returned null.\");\n        var table = client.GetTableClient(_options.TableName);\n        await table.CreateIfNotExistsAsync(cancellationToken).ConfigureAwait(false);\n        _tableClientProvider.SetTableClient(table);\n    }\n\n    public IJournalStorage CreateStorage(JournalId journalId)\n    {\n        if (journalId.IsDefault)\n        {\n            throw new ArgumentException(\"The journal id must not be the default value.\", nameof(journalId));\n        }\n\n        return new AzureTableJournalStorage(_shared, journalId);\n    }\n\n    public async IAsyncEnumerable<JournalId> ListAsync(\n        JournalId prefix = default,\n        [EnumeratorCancellation] CancellationToken cancellationToken = default)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/Azure/Orleans.Journaling.AzureStorage/AzureTableJournalStorageProvider.cs#L25-L61","documentation":"Thrown during Initialize when the configured CreateClient factory delegate returns null after awaiting. The contract requires the factory to produce a non-null TableServiceClient; a null result indicates a broken factory and is rejected immediately.","triggerScenarios":"A custom ConfigureTableServiceClient callback returns null (e.g. ct => Task.FromResult<TableServiceClient>(null)) due to a failed internal client construction or a misplaced default.","commonSituations":"A factory that conditionally returns null on missing config instead of throwing; a dependency-injection resolver returning null; a refactor that dropped the 'new TableServiceClient(...)' expression.","solutions":["Ensure the factory always returns a valid TableServiceClient instance; throw inside the factory if construction fails.","Replace a null-returning factory with a simpler ConfigureTableServiceClient overload (connection string / Uri / credential).","Add a null check inside the factory that throws a descriptive exception before returning."],"exampleFix":"// before\noptions.ConfigureTableServiceClient(ct => Task.FromResult<TableServiceClient>(null!));\n// after\noptions.ConfigureTableServiceClient(ct => Task.FromResult(new TableServiceClient(connectionString)));","handlingStrategy":"validation","validationCode":"var client = await options.CreateClient!(ct);\nif (client is null) throw new InvalidOperationException(\"Client factory returned null.\");","typeGuard":"static bool FactoryReturnsNonNull(Func<CancellationToken, Task<TableServiceClient>> f, CancellationToken ct) => f(ct).GetAwaiter().GetResult() is not null;","tryCatchPattern":null,"preventionTips":["Inside a custom factory, never return null; throw on construction failure.","Prefer the built-in ConfigureTableServiceClient overloads.","Unit-test the factory in isolation to confirm it yields a client."],"tags":["azure-table-storage","journaling","configuration","client-setup","null-return"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}