Bucket app-data is not bootstrapped

I am using the latest .NET SDK 3.0.1 and Enterprise Edition 6.5.1 build 6299. The following gives me an exception:

_collections = bucket.DefaultCollection();
await _collections.InsertAsync(Guid.NewGuid().ToString(), objDoc);

The exception is: Bucket app-data is not bootstrapped.

I am able to insert to the same bucket using SDK 2.7
await bucket.InsertAsync(objDoc);

I can’t make sense of the error, do I need to set up a collection in order to start using the latest version?

Thanks,

@etoilexxx Can you provide the bootstrap code you used for the cluster and bucket?

1 Like

Forgive my ignorance, by bootstrap code you mean C# code instantiation done in my .NET Core 3.0.1 app?

@etoilexxx Sorry for the confusion. I mean all of the code used to configure the Couchbase SDK and get access to the bucket object you’re using in your above example. For example, if you’re using Couchbase.Extensions.DependencyInjection then your ServiceCollection registration statements and your config.json file.

I am not using any couchbase extensions:
AppSetting.config:
“couchbase”: {
“ConnectionString”: “couchbase://localhost”,
“UserName”: “username”,
“Password”: “pass”,
“buckets”: [ “app-data” ]
}

Startup/Configure Services

var section = configuration.GetSection(“couchbase”);
services.Configure(options => configuration.GetSection(“couchbase”).Bind(options));

services.AddSingleton(c =>
{
ClusterOptions options = c.GetService<IOptions>().Value;
return Cluster.ConnectAsync(options).Result;
});

services.AddScoped(c =>
{
ClusterOptions options = c.GetService<IOptions>().Value;
var cluster = c.GetService();
return cluster.BucketAsync(options.Buckets[0]).Result;
});

In my repository: I inject the bucket and use the following:

await _bucket.DefaultCollection().UpsertAsync(task.Id.ToString(), new
{
Name = task.Name,
Type = task.Category,
CreatedUID = task.CreatedAt,
ModifiedUID = task.CreatedAt
});

I’m not certain, but I’m not really sure how that bootstrap code you provided is working. For example, c.GetService<IOptions>().Value wouldn’t get the couchbase options object, it would need to be c.GetService<IOptions<ClusterOptions>>().Value. It also has problems with potential thread-pool deadlocks calling .Result in a synchronous method.

I would strongly recommend looking at this NuGet package, which is designed to do all the wire-up with dependency injection for you. It is an official package for .NET provided by Couchbase. https://www.nuget.org/packages/Couchbase.Extensions.DependencyInjection/

If not, then I’d look at how it does some of the DI registration and model your process on it.

2 Likes

Sorry that is not what I typed, somehow the copy pasting altered my code:
This is what I have and wanted to paste:

var section = configuration.GetSection("couchbase");
services.Configure<ClusterOptions>(options => configuration.GetSection("couchbase").Bind(options));

services.AddSingleton<ICluster>(c =>
{
	ClusterOptions options = c.GetService<IOptions<ClusterOptions>>().Value;
	return Cluster.ConnectAsync(options).Result;
});

services.AddScoped<IBucket>(c =>
{
	ClusterOptions options = c.GetService<IOptions<ClusterOptions>>().Value;
	var cluster = c.GetService<ICluster>();
	return cluster.BucketAsync(options.Buckets[0]).Result;
});

Interesting, if you try to paste my code without code bloc or formatting, it strips away words. I will look at the Couchbase DI extension and let you know.