aws / aws-sdk-net

The official AWS SDK for .NET. For more information on the AWS SDK for .NET, see our web site:
http://aws.amazon.com/sdkfornet/
Apache License 2.0
2.07k stars 860 forks source link

AmazonRekognitionClient instantiation failure: "Cannot find a handler of type EndpointResolver" #3073

Closed adamron closed 1 year ago

adamron commented 1 year ago

Describe the bug

I am unable to use the AWS Rekognition v3 Client.

I have found similar issues with AWS service clients in the past, which makes me suspect that this is an upstream issue.

https://github.com/aws/aws-xray-sdk-dotnet/issues/267

Expected Behavior

Expectation was to instantiate the AWS rekognition client.

Current Behavior

Exception has occurred: CLR/System.InvalidOperationException
An exception of type 'System.InvalidOperationException' occurred in AWSSDK.Core.dll but was not handled in user code: 'Cannot find a handler of type EndpointResolver'
   at Amazon.Runtime.Internal.RuntimePipeline.AddHandlerAfter[T](IPipelineHandler handler)
   at Amazon.Runtime.Internal.RuntimePipelineCustomizerRegistry.ApplyCustomizations(Type type, RuntimePipeline pipeline)
   at SwipedOn.Infrastructure.AssetStorage.AssetStorageContextFactory.ConfigureAmazonRekognition(String accessKey, String secret, String region) in /Users/adamron/dev/vagrant-setup/zoolander/src/2. Infrastructure/AssetStorage/SwipedOn.Infrastructure.AssetStorage/AssetStorageContextFactory.cs:line 56
   at SwipedOn.Infrastructure.AssetStorage.AssetStorageContextFactory.<>c__DisplayClass0_0.<Configure>b__1(IServiceProvider x) in /Users/adamron/dev/vagrant-setup/zoolander/src/2. Infrastructure/AssetStorage/SwipedOn.Infrastructure.AssetStorage/AssetStorageContextFactory.cs:line 36
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.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.VisitScopeCache(ServiceCallSite callSite, 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__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at SwipedOn.Infrastructure.AssetStorage.AssetStorageContextFactory.<>c__DisplayClass0_0.<Configure>b__2(IServiceProvider x) in /Users/adamron/dev/vagrant-setup/zoolander/src/2. Infrastructure/AssetStorage/SwipedOn.Infrastructure.AssetStorage/AssetStorageContextFactory.cs:line 38
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   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__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass7_0.<CreateActivator>b__0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()

Reproduction Steps

Failure occurs when instantiating the rekognition client

public static IAmazonRekognition ConfigureAmazonRekognition(string accessKey, string secret, string region)
    {
        var credential = new BasicAWSCredentials(accessKey, secret);
        var regionEndPoint = RegionEndpoint.GetBySystemName(region);

        var rekclient = new AmazonRekognitionClient(credential, regionEndPoint); // Fails here

        return rekclient;
    }

This code is almost exactly identical to the s3 client instantiation (AWSSDK.S3 version 3.7.9.3) which works as expected:

    public static IAmazonS3 ConfigureAmazonS3(string accessKey, string secret, string region)
    {
        var credential = new BasicAWSCredentials(accessKey, secret);
        var regionEndPoint = RegionEndpoint.GetBySystemName(region);
        var s3client = new AmazonS3Client(credential, regionEndPoint);

        return s3client;
    }

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.Rekognition 3.7.201.3

Targeted .NET Platform

.NET 6.0 (Core)

Operating System and version

Mac M1, macOS Sonoma

bhoradc commented 1 year ago

Hi @adamron,

Thanks for reporting the issue. I am unable to reproduce the exception in below environment.

.NET SDK & service version: AWSSDK.Rekognition 3.7.201.3, AWSSDK.Core 3.7.204.4 .NET framework: .NET 6 (core) OS: Mac M1

Here is the code that I used for reproducing this issue.

using Amazon.Runtime;
using Amazon;
using Amazon.Rekognition;
using Amazon.Rekognition.Model;

namespace Issue_3073;
class Program
{
    static async Task Main(string[] args)
    {  
        var rekresult = ConfigureRekognition("accesskey", "secretkey", "us-east-1");

        var response = await rekresult.CreateCollectionAsync(new CreateCollectionRequest
        {
            CollectionId = "firstphotos"
        });

        string collectionArn = response.CollectionArn;
        int statusCode = response.StatusCode;

        Console.WriteLine(collectionArn+ " "+statusCode);
    }

    public static IAmazonRekognition ConfigureRekognition(string accessKey, string secret, string region)
    {
        var credential = new BasicAWSCredentials(accessKey, secret);
        var regionEndPoint = RegionEndpoint.GetBySystemName(region);
        var rekclient = new AmazonRekognitionClient(credential, regionEndPoint);

        return rekclient;
    }
}

Execution result: aws:rekognition:us-east-1:account:collection/firstphotos 200

Can you please take a look at above code sample and suggest if i am missing anything here? Or kindly provide us with a minimal code that I can use to reproduce this issue.

Regards, Chaitanya

github-actions[bot] commented 1 year ago

This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.