Exception when try to get a bucket

Hi,

I m facing with an exception when I try to open the bucket. This is an ASP project.

The code is realy simple

   private static bool IsInitialized;
   private static string BucketName;

   private static void Initialize()
   {
       if (IsInitialized)
           return;

       // Build the configuration for the bucket
       var configuration = new ClientConfiguration();
       
       //Clear default values
       configuration.BucketConfigs.Clear();
       configuration.Servers.Clear();

       //Bucket config
       BucketName = RoleEnvironment.GetConfigurationSettingValue("CouchbaseBucket");
       var bucketConfig = new BucketConfiguration
       {
           BucketName = BucketName,
            Password = RoleEnvironment.GetConfigurationSettingValue("CouchbaseBucketPassword"),
            UseSsl = false,
            PoolConfiguration = new PoolConfiguration {
                MinSize = 1,
                MaxSize = 20
            }
       };
       configuration.BucketConfigs.Add(
           bucketConfig.BucketName,
           bucketConfig
       );

       //Add servers from config
       var servers = RoleEnvironment.GetConfigurationSettingValue("CouchbaseServers").Split(',');
       foreach (var server in servers)
       {
           var uri = new System.Uri("http://" + server + ":8091/pools");
           configuration.Servers.Add(uri);
       }

       ClusterHelper.Initialize(configuration);
       IsInitialized = true;
   }

   public static IBucket GetBucket()
   {
       if (!CouchbaseManager.IsInitialized)
           Initialize();

       return ClusterHelper.GetBucket(BucketName);  
   }

The error occurs at line

return ClusterHelper.GetBucket(BucketName);  

The exception details are

System.AggregateException was unhandled by user code
HResult=-2146233088
Message=Could not bootstrap - check inner exceptions for details.
Source=Couchbase.NetClient
StackTrace:
in Couchbase.Core.ClusterController.CreateBucket(String bucketName, String password)
in CouchBaseRepository`1.OpenBucket() in CouchBaseRepository.cs:ligne 32

in SyncInvokeAcceptIpTracking(Object , Object , Object )
in System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object inputs, Object& outputs)
in System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
InnerException: System.AggregateException
HResult=-2146233088
Message=One or many errors occurs
Source=Couchbase.NetClient
StackTrace:
in Couchbase.Configuration.Server.Providers.CarrierPublication.CarrierPublicationProvider.GetConfig(String bucketName, String password)
in Couchbase.Core.ClusterController.CreateBucket(String bucketName, String password)
InnerException: System.NullReferenceException
HResult=-2147467261
Message=Object reference not set to an instance of an object
Source=Couchbase.NetClient
StackTrace:
in Couchbase.Configuration.Server.Providers.CarrierPublication.CarrierPublicationProvider.GetConfig(String bucketName, String password)

Someone has an idea why I get this error ?

@fx_algrain

I cut and pasted this code into console app, replacing the calls to RoleEnvironment.GetConfigurationSettingValue with hardcoded values and it worked. You might want make sure that the correct values are being stored in the configuration file. Is there more to the stacktrace?

You can also create a Jira ticket and attach an example project and I take a look at it.

-Jeff

In fact the code was working well and stop to work without a reason on production.

The app is hosted in Azure. And we are almost sure the production stop to work after an instance update.
In Azure, hosts are auto updated.

Also I think you need to test on an ASP project.

I wll try to create a simple project with the same issue.

@jmorris

I open the ticket Loading...

That is important information! So, the app was runnning in Aure and there was an instance update? Would it be possible to post the logs around the time it failed to the ticket?

No sorry I don’t have the log.

I reproduce the bug outside of Azure.

@fx_algrain

Ok, thanks!

Please be aware that when using a configuration file, the file can depend on your build configuration.

This will typically mean that switching between “Debug” and “Release” build will point to different config files.

Therefore, please check the value returned when calling:

Hope this helps