{"record":{"id":"28543a8e9751c73e","repo":"dotnet/orleans","slug":"value-cannot-be-null-parameter-createclient","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'createClient')","messagePattern":"Value cannot be null\\. \\(Parameter 'createClient'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Azure/Shared/Cosmos/CosmosOptions.cs","lineNumber":116,"sourceCode":"\n    /// <summary>\n    /// Configures the Cosmos DB client.\n    /// </summary>\n    /// <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>\n    /// <param name=\"authKeyOrResourceToken\">The Cosmos account key or resource token to use to create the client.</param>\n    /// <see cref=\"CosmosClient(string, TokenCredential, CosmosClientOptions)\"/>\n    public void ConfigureCosmosClient(string accountEndpoint, string authKeyOrResourceToken)\n    {\n        CreateClient = _ => new(new CosmosClient(accountEndpoint, authKeyOrResourceToken, ClientOptions));\n    }\n\n    /// <summary>\n    /// Configures the Cosmos DB client.\n    /// </summary>\n    /// <param name=\"createClient\">The delegate used to create the Cosmos DB client.</param>\n    public void ConfigureCosmosClient(Func<IServiceProvider, ValueTask<CosmosClient>> createClient)\n    {\n        CreateClient = createClient ?? throw new ArgumentNullException(nameof(createClient));\n    }\n\n    /// <summary>\n    /// Factory method for creating a <see cref=\"CosmosClient\"/>.\n    /// </summary>\n    internal Func<IServiceProvider, ValueTask<CosmosClient>> CreateClient { get; private set; } = null!;\n}\n\n/// <summary>\n/// Functionality for executing operations using the Cosmos DB client.\n/// </summary>\npublic interface ICosmosOperationExecutor\n{\n    /// <summary>\n    /// Executes the provided Cosmos DB operation.\n    /// </summary>\n    /// <typeparam name=\"TArg\">The function argument.</typeparam>\n    /// <typeparam name=\"TResult\">The result value.</typeparam>","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/Azure/Shared/Cosmos/CosmosOptions.cs#L98-L134","documentation":"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.","triggerScenarios":"Calling ConfigureCosmosClient(null) or passing a delegate resolved from a nullable DI service that was never registered.","commonSituations":"Refactor that drops the factory assignment; conditional configuration branch that leaves the delegate null; copy-paste from a sample that omits the lambda.","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."],"exampleFix":"// before\noptions.ConfigureCosmosClient(null);\n\n// after\noptions.ConfigureCosmosClient(_ => new(new CosmosClient(endpoint, key, options.ClientOptions)));","handlingStrategy":"validation","validationCode":"if (createClient is null) throw new ArgumentNullException(nameof(createClient));\noptions.ConfigureCosmosClient(createClient);","typeGuard":"static bool IsValidFactory(Func<IServiceProvider, ValueTask<CosmosClient>>? f) => f is not null;","tryCatchPattern":null,"preventionTips":["Build the factory lambda inline at the call site.","If you only have endpoint+key, use the string overload of ConfigureCosmosClient."],"tags":["cosmos","configuration","null-argument","azure"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}