{"record":{"id":"eba38f5b60845378","repo":"dotnet/orleans","slug":"this-instance-has-not-been-initialized-ensure-tha-eba38f","errorCode":null,"errorMessage":"This instance has not been initialized. Ensure that InitializeGatewayListProvider is called to initialize this instance before use.","messagePattern":"This instance has not been initialized\\. Ensure that InitializeGatewayListProvider is called to initialize this instance before use\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Cassandra/Orleans.Clustering.Cassandra/CassandraGatewayListProvider.cs","lineNumber":46,"sourceCode":"\n    bool IGatewayListProvider.IsUpdatable => true;\n\n    public CassandraGatewayListProvider(\n        IOptions<ClusterOptions> clusterOptions,\n        IOptions<GatewayOptions> gatewayOptions,\n        IOptions<CassandraClusteringOptions> options,\n        IOptions<ClusterMembershipOptions> clusterMembershipOptions,\n        IServiceProvider serviceProvider)\n    {\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    {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/Cassandra/Orleans.Clustering.Cassandra/CassandraGatewayListProvider.cs#L28-L64","documentation":"InvalidOperationException from the Session property getter on CassandraGatewayListProvider: the backing _session is null because IGatewayListProvider.InitializeGatewayListProvider has not completed. The message (via NotInitializedMessage) tells you to call InitializeGatewayListProvider. Identical pattern to the clustering table's Session guard.","triggerScenarios":"Calling GetGateways() (or any code path that reads Session) before InitializeGatewayListProvider finishes assigning _session. The provider caches results but the first access to Session still requires initialization.","commonSituations":"Using the Cassandra gateway provider without registering it through the client hosting extension, or a client that resolves the provider and calls GetGateways in a test before initialization. Also when CreateSessionAsync returned null earlier (see error 353), leaving _session unset.","solutions":["Register the provider via the Orleans client hosting extension (UseCassandraGatewayListProvider / AddCassandraClustering) so the runtime calls InitializeGatewayListProvider.","In tests, await InitializeGatewayListProvider before calling GetGateways.","If initialization is failing earlier, inspect logs for CreateSessionAsync/EnsureTableExistsAsync errors and fix those first."],"exampleFix":"// before\nvar gw = host.Services.GetRequiredService<IGatewayListProvider>();\nawait gw.GetGateways(); // throws: Session null\n\n// after\nvar gw = host.Services.GetRequiredService<IGatewayListProvider>();\nawait gw.InitializeGatewayListProvider();\nawait gw.GetGateways();","handlingStrategy":"validation","validationCode":"await gw.InitializeGatewayListProvider();\nawait gw.GetGateways();","typeGuard":null,"tryCatchPattern":"try { await gw.GetGateways(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"InitializeGatewayListProvider\"))\n{ logger.LogError(ex, \"Gateway provider used before init\"); throw; }","preventionTips":["Register the Cassandra gateway provider via the client hosting extension","Await InitializeGatewayListProvider in tests","Check for earlier CreateSessionAsync failures"],"tags":["initialization","cassandra","gateway","client","usage-ordering"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}