{"record":{"id":"6fb16c71bbadbf6c","repo":"dotnet/efcore","slug":"none-of-connection-string-credentialtoken-accoun","errorCode":null,"errorMessage":"None of connection string, CredentialToken, account key or account endpoint were specified. Specify a set of connection details.","messagePattern":"None of connection string, CredentialToken, account key or account endpoint were specified\\. Specify a set of connection details\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs","lineNumber":102,"sourceCode":"\n        if (options.HttpClientFactory != null)\n        {\n            configuration.HttpClientFactory = options.HttpClientFactory;\n        }\n\n        if (options.EnableBulkExecution != null)\n        {\n            configuration.AllowBulkExecution = options.EnableBulkExecution.Value;\n        }\n\n        configuration.EnableContentResponseOnWrite = options.EnableContentResponseOnWrite == true;\n\n        _client = options switch\n        {\n            { ConnectionString: not null and not \"\" } => new CosmosClient(options.ConnectionString, configuration),\n            { TokenCredential: not null } => new CosmosClient(options.AccountEndpoint, options.TokenCredential, configuration),\n            { AccountEndpoint: not null } => new CosmosClient(options.AccountEndpoint, options.AccountKey, configuration),\n            _ => throw new InvalidOperationException(CosmosStrings.ConnectionInfoMissing)\n        };\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual CosmosClient Client\n        => _client;\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs#L84-L120","documentation":"Thrown in the SingletonCosmosClientWrapper constructor when none of the Cosmos connection inputs are supplied. The constructor pattern-matches on options: ConnectionString first, then TokenCredential (+AccountEndpoint), then AccountEndpoint (+AccountKey); if all are null/empty it throws because there is no way to construct a CosmosClient. At least one valid connection detail set is mandatory for the Cosmos provider.","triggerScenarios":"Calling UseCosmos with a database name but omitting the connection string, account endpoint, account key, and token credential. Or passing an empty string for ConnectionString (empty is treated as null by the pattern guard).","commonSituations":"Relying on a configuration section that is missing or misnamed (e.g., binding the wrong key). Environment-specific config where the Cosmos connection string is injected only in Production but the app runs in Development without it. Using Azure RBAC/TokenCredential but forgetting to also set AccountEndpoint. Empty-string connection strings from IConfiguration that look non-null but are treated as absent.","solutions":["Provide a non-empty connection string to UseCosmos, e.g. optionsBuilder.UseCosmos(connectionString, databaseName).","Or provide accountEndpoint + accountKey, or accountEndpoint + tokenCredential.","Validate at startup that the connection string is non-empty before building the DbContext (it may be bound from a missing config key)."],"exampleFix":"// before - connection string from config is null/empty\nvar cosmosSection = config.GetSection(\"WrongKey\");\noptionsBuilder.UseCosmos(cosmosSection[\"ConnectionString\"], \"MyDb\"); // throws\n\n// after - bind the correct non-empty value\nvar connStr = config.GetConnectionString(\"Cosmos\")\n    ?? throw new InvalidOperationException(\"Cosmos connection string missing\");\noptionsBuilder.UseCosmos(connStr, \"MyDb\");","handlingStrategy":"validation","validationCode":"var connStr = config.GetConnectionString(\"Cosmos\");\nif (string.IsNullOrWhiteSpace(connStr))\n    throw new InvalidOperationException(\"Cosmos connection string is missing in configuration.\");\noptionsBuilder.UseCosmos(connStr, databaseName);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the connection string is non-empty at startup before building the DbContext.","Provide connection details in all environments (Development included), or fail fast with a clear message.","When using TokenCredential, also set AccountEndpoint.","Bind configuration with a fallback that throws an explicit error."],"tags":["cosmos","connection","configuration","startup"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}