Intermittent InvalidOperationException in Dependency Injection

Description

From forums: https://forums.couchbase.com/t/intermittent-invalidoperationexception-in-dependency-injection/27168

I’m using CouchbaseNetClient v3.0.4 and Couchbase.Extensions.DependencyInjection v3.0.4.811, both from Nuget… I’m seeing some intermittent errors when I call GetBucketAsync. If I retry the operation it will eventually be successful.

My code is pretty simple: I call AddCouchbase(Configuration.GetSection("Couchbase")) in Startup.ConfigureServices. I inject IBucketProvider and then do var bucket = await _bucketProvider.GetBucketAsync("mybucket");

Here’s the stack trace:

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at Couchbase.Core.DI.CouchbaseServiceProvider..ctor(IEnumerable`1 serviceFactories)
at Couchbase.ClusterOptions.BuildServiceProvider()
at Couchbase.Core.ClusterContext..ctor(ICluster cluster, CancellationTokenSource tokenSource, ClusterOptions options)
at Couchbase.Cluster..ctor(ClusterOptions clusterOptions)
at Couchbase.Cluster.ConnectAsync(ClusterOptions options)
at Couchbase.Extensions.DependencyInjection.Internal.ClusterProvider.GetClusterAsync()
at Couchbase.Extensions.DependencyInjection.Internal.BucketProvider.<GetBucketAsync>b__4_0(String name)

I’d really appreciate any help you can offer. Thanks, and have a good weekend.

Environment

None

Gerrit Reviews

None

Release Notes Description

None

Activity

Show:
Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Story Points

Components

Fix versions

Affects versions

Priority

Instabug

Open Instabug

PagerDuty

Sentry

Zendesk Support

Created August 28, 2020 at 11:11 PM
Updated September 11, 2020 at 6:50 PM
Resolved September 11, 2020 at 6:50 PM
Instabug