DI error on distributed cache (NET SDK 3.0X)

Hi everyone,

I need to use Couchbase as Distributed Cache for a .Net core application.
The ‘how to’ guide is outdated (2017) and does not apply anymore with the .Net 3.05 sdk.
So I used the last version available on Github (nuget package is outdated too), and after my first debugging, an error occures at startup :

Unable to resolve service for type ‘Couchbase.Extensions.Caching.ICouchbaseCacheBucketProvider’ while attempting to activate ‘Couchbase.Extensions.Caching.Internal.DefaultCouchbaseCacheCollectionProvider’

Here is my code int the ConfigureServices(IServiceCollection serviceCollection) method, where I setup things for dependency injection

 serviceCollection.AddCouchbase(opt => {
            .WithCredentials(username: "MyDistributedCache", password: "xxxxxxxxxx")
        ) ;

 serviceCollection.AddDistributedCouchbaseCache(setup => setup.LifeSpan = TimeSpan.FromMinutes(120));

My user and my bucket have the same name, as it was advised in the ‘how to’ guide.

I checked the .Net SDK extensions source code in the github repo, and I can see this part of code which seems interesting

        services.TryAddSingleton<ICouchbaseCacheCollectionProvider, DefaultCouchbaseCacheCollectionProvider>();

What am I missing ? Maybe I have to specify something for the DefaultCoucheBaseCollectionProvider ?

Thanks for your help.

PS : By the way, if one of the nugget packgae maintainer reads this message, the nugget package is outdated too, and its reference to an old version of ITracing causes a CS0433 issue code using an updated version of ITracing.


The work to update the distributed caching provider to be compatible with SDK 3.x is still a work in progress. As such, NuGet packages and updated documentation have not yet been released. So your approach of building from source is correct.

To make it work, please do one of the following:

  1. Use the other overload to AddDistributedCouchbaseCache which accepts a bucket name parameter
  2. Manually register an implementation of ICouchbaseCacheBucketProvider

Please keep us informed of any other issues you have since it will help us when finishing the SDK 3.x work.

Hi @btburnett3,

Thank you for this quick answer ! I used the first option and it works :

 serviceCollection.AddCouchbase(opt => {
            .WithCredentials(username: "MyDistributedCache", password: "xxxxxxx");
        ) ;
        serviceCollection.AddDistributedCouchbaseCache("MyDistributedCache",setup => setup.LifeSpan = TimeSpan.FromMinutes(120));

I had to change the connectionstring to reach the coucbase server ( the “http” way seems obsolete).

Thanks again !