Polly icon indicating copy to clipboard operation
Polly copied to clipboard

[Bug]: System.InvalidOperationException thrown when registering with AddResiliencePipeline in .NET 8 Isolated Function App

Open CSharpFiasco opened this issue 1 year ago • 1 comments

Describe the bug

Seems to be related to the following bug in the .NET 8 runtime: https://github.com/dotnet/runtime/issues/95789.

Expected behavior

I would expect the function app to register the single event hub trigger

Actual behavior

Exception thrown: 'System.InvalidOperationException' in Microsoft.Extensions.DependencyInjection.Abstractions.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.Extensions.DependencyInjection.Abstractions.dll
This service descriptor is keyed. Your service provider may not support keyed services.

Steps to reproduce

using Microsoft.Extensions.Hosting;
using Polly;
using Polly.Retry;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices((builder, services) =>
    {
        services.AddResiliencePipeline("my-pipeline", (resiliencePipeLineBuilder, context) =>
        {
            resiliencePipeLineBuilder.InstanceName = "my-pipeline";
            resiliencePipeLineBuilder.AddRetry(new RetryStrategyOptions());
        });
    })
    .Build();

host.Run();

Exception(s) (if any)

 	Microsoft.Extensions.DependencyInjection.Abstractions.dll!Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ThrowKeyedDescriptor()	Unknown
 	Microsoft.Extensions.DependencyInjection.Abstractions.dll!Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ImplementationInstance.get()	Unknown
 	Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.Populate()	Unknown
 	Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CallSiteFactory(System.Collections.Generic.ICollection<Microsoft.Extensions.DependencyInjection.ServiceDescriptor> descriptors)	Unknown
 	Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceProvider.ServiceProvider(System.Collections.Generic.ICollection<Microsoft.Extensions.DependencyInjection.ServiceDescriptor> serviceDescriptors, Microsoft.Extensions.DependencyInjection.ServiceProviderOptions options)	Unknown
 	Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.DependencyInjection.ServiceProviderOptions options)	Unknown
 	Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection containerBuilder)	Unknown
 	Microsoft.Extensions.Hosting.dll!Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter<Microsoft.Extensions.DependencyInjection.IServiceCollection>.CreateServiceProvider(object containerBuilder)	Unknown
 	Microsoft.Extensions.Hosting.dll!Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()	Unknown
 	Microsoft.Extensions.Hosting.dll!Microsoft.Extensions.Hosting.HostBuilder.Build()	Unknown
>	MyEvents.dll!Program.<Main>$(string[] args) Line 5	C#

Polly version

8.4.0

.NET Version

8.0.204

Anything else?

I've based my code around the following guidelines: https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=windows#start-up-and-configuration. Let me know if you'd like me to spin up a simplified project

CSharpFiasco avatar May 14 '24 02:05 CSharpFiasco

I tried to reproduce the issue in a console application.

  • When I run the application without the ConfigureFunctionsWorkerDefaults call then it works fine without any exception.
  • When I run the application with the ConfigureFunctionsWorkerDefaults call then I get a different InvalidOperationException:

System.InvalidOperationException: The gRPC channel URI 'http://:' could not be parsed.

I don't see anything which is Polly related in either StackTraces.

Could you please run your code but now without the AddResiliencePipeline call?

peter-csala avatar May 22 '24 07:05 peter-csala

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

github-actions[bot] avatar Jul 22 '24 01:07 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Aug 05 '24 01:08 github-actions[bot]