Can't use Dependency injection

@Ramirag just looking at your error looks like the Dependency is being added twice “Duplicate type name within an assembly.”

I have only single place with definition. And this error occurs after first calling. Probably code is trying to create one more type.

@Ramirag -

Which version of Couchbase Dependency Injection are you using?

v 3.0.3
20 chars limit :slight_smile:

@Ramirag - can you try using Couchbase.Extensions.DependencyInjection 3.0.1 and then upgrading the CouchbaseNetClient dependency to 3.0.3 and let us know the result?

The same result. And I’ve used CouchbaseNetClient 3.0.3 all this time.

@btburnett3 - any ideas?

@jmorris I believe this is fixed in Couchbase.Extensions.DependencyInjection 3.0.3

@jmorris The best theory I’ve got is that it’s related to the use of the public key token instead of the actual public key in the InternalsVisibleTo attribute.

This is how it’s written in 3.0.3:

But that appears to just be the short public key token applied to the PublicKey value. Based on my experience, I thought it had to be the full length public key.

Also, I think the key is incorrect for DynamicProxyGenAssembly2. It should be the key used by Castle.Core DynamicProxy, not the Couchbase key:

[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]

I’va alson run into the same issue

Try this package: https://www.nuget.org/packages/Couchbase.Extensions.DependencyInjection/3.0.3.729

I am getting the same exceptions.

@Ramirag -

I am not sure what is going on here, then. Note that I tested (using VS2019 Web App netcoreapp3.1) all of the builds locally and all worked. Can you describe the environment? Application type and .NET Version, etc?

Strange, all the same. I’ve loaded simple test solution https://github.com/Ramirag/CouchbaseDI

I am also seeing the same issue. VS2019, Target Framework netcoreapp3.1,

Couchbase packages:
“Couchbase.Extensions.DependencyInjection” Version=“3.0.3.729”
“CouchbaseNetClient” Version=“3.0.3”

Exception Details:

System.TypeLoadException
HResult=0x80131522
Message=Access is denied: ‘Couchbase.Extensions.DependencyInjection.Internal.NamedBucketProvider’.
Source=System.Private.CoreLib
StackTrace:
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
at Couchbase.Extensions.DependencyInjection.Internal.NamedBucketProxyGenerator.CreateProxyType(Type interfaceType)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at Couchbase.Extensions.DependencyInjection.Internal.NamedBucketProxyGenerator.GetProxy[T](IBucketProvider bucketProvider, String bucketName)
at Couchbase.Extensions.DependencyInjection.ServiceCollectionExtensions.<>c__DisplayClass2_01.<AddCouchbaseBucket>b__0(IServiceProvider serviceProvider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
at TestConnectAppSettings.Program.d__8.MoveNext() in C:\Xdv\git\personal\TestCouchbase-Sdk3.0\TestConnect-AppSettings\Program.cs:line 37
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at TestConnectAppSettings.Program.(String args)

This exception was originally thrown at this call stack:
System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
Couchbase.Extensions.DependencyInjection.Internal.NamedBucketProxyGenerator.CreateProxyType(System.Type)
System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>.GetOrAdd(TKey, System.Func<TKey, TValue>)
Couchbase.Extensions.DependencyInjection.Internal.NamedBucketProxyGenerator.GetProxy(Couchbase.Extensions.DependencyInjection.IBucketProvider, string)
Couchbase.Extensions.DependencyInjection.ServiceCollectionExtensions.AddCouchbaseBucket.AnonymousMethod__0(System.IServiceProvider)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<TArgument, TResult>.VisitCallSiteMain(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite, TArgument)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext)

[Call Stack Truncated]

I was mistaken. When I pull the source code, add project reference, and compile myself, it works fine. When I use the NuGet package, I’m getting the same error that others in this thread are seeing.

I still cannot reproduce even using the NuGet package. Perhaps its related to usage? Can somebody post an example project illustrating the issue?

-Jeff

I’ve written a link to github later.

1 Like

@Ramirag -

Thanks, I can recreate now; I wasn’t using a custom INamedBucketProvider. I’ll push a fixed 3.0.4 with dependencies on Couchbase SDK 3.0.4 later this week.

-Jeff

It was a signing issue, this package should solve the problem:
https://www.nuget.org/packages/Couchbase.Extensions.DependencyInjection/3.0.4.811

1 Like