Skip to content

NullReferenceException when ClientKey is wrong #43

@gioalhaz

Description

@gioalhaz

If ClientKey is wrong then code below throws exception

var context = new Context()
{
    Enabled = true,
    ClientKey = SDKConnectionClientKey,
    Attributes = attrs,
    LoggerFactory = loggerFactory
};

 
 var featureFlags = new GrowthBook.GrowthBook(context);
 
 var task = featureFlags.LoadFeatures();
 task.Wait();
 
 featureFlags.IsOn("AdvancedMode");

Error log below:

dbug: GrowthBook.Api.FeatureRefreshWorker[0]
      Features GrowthBook API endpoint: 'https://cdn.growthbook.io/api/features/sdk-****'
dbug: GrowthBook.Api.FeatureRefreshWorker[0]
      Features GrowthBook API endpoint (Server Sent Events): 'https://cdn.growthbook.io/api/features/sdk-****'
info: GrowthBook.GrowthBook[0]
      Loading features from the repository
info: GrowthBook.Api.FeatureRepository[0]
      Getting features from repository, verifying cache expiration and option to force refresh
info: GrowthBook.Api.FeatureRepository[0]
      Cache has expired or option to force refresh was set, refreshing the cache from the API
dbug: GrowthBook.Api.FeatureRepository[0]
      Cache expired: 'True' and option to force refresh: '(null)'
info: GrowthBook.Api.FeatureRefreshWorker[0]
      Making an HTTP request to the default Features API endpoint 'https://cdn.growthbook.io/api/features/sdk-****'
info: GrowthBook.Api.FeatureRepository[0]
      Either cache currently has no features or the option to wait for completion was set, waiting for cache to refresh
dbug: GrowthBook.Api.FeatureRepository[0]
      Feature count: '0' and option to wait for completion: '(null)'
fail: GrowthBook.Api.FeatureRefreshWorker[0]
      HTTP request to default Features API endpoint 'https://cdn.growthbook.io/api/features/sdk-****' resulted in a BadRequest status code
info: GrowthBook.GrowthBook[0]
      Loading features has completed, retrieved '' features
fail: GrowthBook.GrowthBook[0]
      Encountered an unhandled exception while executing 'EvalFeature'
      System.NullReferenceException: Object reference not set to an instance of an object.
         at GrowthBook.GrowthBook.EvalFeature(String featureId)

Other then that, there is no way to determine was LoadFeatures successful or not. No result code, no error code, nothing :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions