{"record":{"id":"a1b5f17dbf4345d7","repo":"dotnet/orleans","slug":"session-created-from-configuration-cassandraclust-a1b5f1","errorCode":null,"errorMessage":"Session created from configuration 'CassandraClusteringOptions' is null.","messagePattern":"Session created from configuration 'CassandraClusteringOptions' is null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/Cassandra/Orleans.Clustering.Cassandra/CassandraGatewayListProvider.cs","lineNumber":55,"sourceCode":"    {\n        _identifier = $\"{clusterOptions.Value.ServiceId}-{clusterOptions.Value.ClusterId}\";\n        _options = options.Value;\n        _serviceProvider = serviceProvider;\n\n        _maxStaleness = gatewayOptions.Value.GatewayListRefreshPeriod;\n        _ttlSeconds = _options.GetCassandraTtlSeconds(clusterMembershipOptions.Value);\n    }\n\n    private ISession Session => _session ?? throw new InvalidOperationException(NotInitializedMessage);\n\n    private OrleansQueries Queries => _queries ?? throw new InvalidOperationException(NotInitializedMessage);\n\n    async Task IGatewayListProvider.InitializeGatewayListProvider()\n    {\n        _session = await _options.CreateSessionAsync(_serviceProvider);\n        if (_session is null)\n        {\n            throw new InvalidOperationException($\"Session created from configuration '{nameof(CassandraClusteringOptions)}' is null.\");\n        }\n\n        _queries = await OrleansQueries.CreateInstance(_session);\n\n        await _queries.EnsureTableExistsAsync(_options.InitializeRetryMaxDelay, _ttlSeconds);\n    }\n    \n    async Task<IList<Uri>> IGatewayListProvider.GetGateways()\n    {\n        if (_cachedResult is not null && _cacheUntil > DateTime.UtcNow)\n        {\n            return [.. _cachedResult];\n        }\n\n        var rows = await Session.ExecuteAsync(await Queries.GatewaysQuery(_identifier, (int)SiloStatus.Active));\n        var result = new List<Uri>();\n\n        foreach (var row in rows)","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/Cassandra/Orleans.Clustering.Cassandra/CassandraGatewayListProvider.cs#L37-L73","documentation":"InvalidOperationException inside InitializeGatewayListProvider when CassandraClusteringOptions.CreateSessionAsync returns a null ISession. The provider cannot fetch gateways without a Cassandra session, so initialization aborts before EnsureTableExistsAsync runs. The message names CassandraClusteringOptions.","triggerScenarios":"CreateSessionAsync returns null for the gateway provider, identical root cause to error 349 but on the client-side gateway list provider.","commonSituations":"Incomplete or misconfigured CreateSessionAsync factory, missing contact points/credentials in options, or a custom factory with a code path that returns null on a fallback. Most often a copy-paste of a sample that was not filled in.","solutions":["Implement CreateSessionAsync to always return a connected ISession (Cluster.Builder()...ConnectAsync(keyspace)).","Validate CassandraClusteringOptions (contact points, keyspace, credentials) at client build time.","Throw inside the factory instead of returning null when session creation genuinely fails."],"exampleFix":"// before\noptions.CreateSessionAsync = _ => Task.FromResult<ISession>(null!);\n\n// after\noptions.CreateSessionAsync = async sp =>\n    await Cluster.Builder().AddContactPoints(cfg.ContactPoints).Build().ConnectAsync(cfg.Keyspace);","handlingStrategy":"validation","validationCode":"options.CreateSessionAsync = async sp =>\n    await Cluster.Builder().AddContactPoints(cfg.ContactPoints).Build().ConnectAsync(cfg.Keyspace)\n    is { } s ? s : throw new InvalidOperationException(\"session null\");","typeGuard":"static async Task<ISession> NonNullSession(Func<Task<ISession?>> factory) =>\n    await factory() ?? throw new InvalidOperationException(\"session factory returned null\");","tryCatchPattern":"try { await gw.InitializeGatewayListProvider(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"is null\"))\n{ logger.LogCritical(ex, \"Cassandra session factory returned null\"); throw; }","preventionTips":["Never return null from CreateSessionAsync","Validate Cassandra options at client build time","Throw inside the factory on failure instead of returning null"],"tags":["cassandra","gateway","config","initialization","client"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}