dotnet/orleans · error · ArgumentNullException
Value cannot be null. (Parameter 'createClient')
Error message
Value cannot be null. (Parameter 'createClient')
What it means
Thrown by CosmosOptions.ConfigureCosmosClient when the supplied client-factory delegate is null. The Cosmos provider needs a non-null factory to lazily construct the CosmosClient.
Source
Thrown at src/Azure/Shared/Cosmos/CosmosOptions.cs:116
/// <summary>
/// Configures the Cosmos DB client.
/// </summary>
/// <param name="accountEndpoint">The account endpoint. In the form of <code>https://{databaseaccount}.documents.azure.com:443/</code>, <see href="https://learn.microsoft.com/rest/api/cosmos-db/cosmosdb-resource-uri-syntax-for-rest"/></param>
/// <param name="authKeyOrResourceToken">The Cosmos account key or resource token to use to create the client.</param>
/// <see cref="CosmosClient(string, TokenCredential, CosmosClientOptions)"/>
public void ConfigureCosmosClient(string accountEndpoint, string authKeyOrResourceToken)
{
CreateClient = _ => new(new CosmosClient(accountEndpoint, authKeyOrResourceToken, ClientOptions));
}
/// <summary>
/// Configures the Cosmos DB client.
/// </summary>
/// <param name="createClient">The delegate used to create the Cosmos DB client.</param>
public void ConfigureCosmosClient(Func<IServiceProvider, ValueTask<CosmosClient>> createClient)
{
CreateClient = createClient ?? throw new ArgumentNullException(nameof(createClient));
}
/// <summary>
/// Factory method for creating a <see cref="CosmosClient"/>.
/// </summary>
internal Func<IServiceProvider, ValueTask<CosmosClient>> CreateClient { get; private set; } = null!;
}
/// <summary>
/// Functionality for executing operations using the Cosmos DB client.
/// </summary>
public interface ICosmosOperationExecutor
{
/// <summary>
/// Executes the provided Cosmos DB operation.
/// </summary>
/// <typeparam name="TArg">The function argument.</typeparam>
/// <typeparam name="TResult">The result value.</typeparam>View on GitHub (pinned to fca799fa70)
Solutions
- Pass a non-null Func<IServiceProvider, ValueTask<CosmosClient>>, e.g. _ => new(new CosmosClient(endpoint, key, options)).
- If you only have an endpoint and key, call ConfigureCosmosClient(string accountEndpoint, string authKeyOrResourceToken) instead.
- Register the factory in DI and resolve it before calling ConfigureCosmosClient.
Example fix
// before options.ConfigureCosmosClient(null); // after options.ConfigureCosmosClient(_ => new(new CosmosClient(endpoint, key, options.ClientOptions)));
Defensive patterns
Strategy: validation
Validate before calling
if (createClient is null) throw new ArgumentNullException(nameof(createClient)); options.ConfigureCosmosClient(createClient);
Type guard
static bool IsValidFactory(Func<IServiceProvider, ValueTask<CosmosClient>>? f) => f is not null;
Prevention
- Build the factory lambda inline at the call site.
- If you only have endpoint+key, use the string overload of ConfigureCosmosClient.
When it happens
Trigger: Calling ConfigureCosmosClient(null) or passing a delegate resolved from a nullable DI service that was never registered.
Common situations: Refactor that drops the factory assignment; conditional configuration branch that leaves the delegate null; copy-paste from a sample that omits the lambda.
Related errors
- credential
- connection
- createConnection
- Configuration for Azure Cosmos DB provider {_name} is invali
- Configuration for Azure Cosmos DB provider {_name} is invali
AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13).
Data as JSON: /api/errors/28543a8e9751c73e.
Report an issue: GitHub.