azure-functions-host icon indicating copy to clipboard operation
azure-functions-host copied to clipboard

Container is disposed and should not be used exception after .NET 6 upgrade

Open lipalath-ms opened this issue 2 years ago • 1 comments

I see the following exception from Azure Function (Service Bus Trigger) after I upgraded azure function from v3 to v4 as part of .NET 6 upgrade:

The host is disposed and cannot be used. Disposed object: 'Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection.ScopedResolver'; Found IListener in stack trace: 'Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListener, Microsoft.Azure.WebJobs.ServiceBus, Version=4.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' Container is disposed and should not be used: Container is disposed.
You may include Dispose stack-trace into the message via:
container.With(rules => rules.WithCaptureContainerDisposeStackTrace()) 

Here are the nuget packages I use:

    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.7.2" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.6.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
    <PackageReference Include="System.Text.Encodings.Web" Version="6.0.0" />

And here is my code in Startup.cs

public override void Configure(IFunctionsHostBuilder builder)
{
            base.Configure(builder);
            builder.Services.AddSingleton<IServiceClient>((services) =>
            {
                return new ServiceClient(CreateAuthProviderFromSecret(value));
            })
            .AddScoped<IGraphRepository, GraphRepository>()            
            .AddSingleton<IBlobRepository, BlobRepository>((s) =>
            {
                var configuration = s.GetService<IConfiguration>();
                var a = configuration["a"];                
                return new BlobRepository(a);
            });
}

lipalath-ms avatar Aug 12 '22 22:08 lipalath-ms

Hi @madelinegordon Hope you are doing well. Could you back to this issue? Our customer has a same one. I think this error can be related to when a Host has started to shutdown and some invocations are still running. Is my understanding correct? and.. If you know any work items/ plans to improve this issue, Could you share with us?

yuna-s avatar Oct 14 '22 01:10 yuna-s

Sorry for the delayed response, we must have missed this issue. Are you still seeing the same problem with all the latest packages?

liliankasem avatar Feb 06 '24 22:02 liliankasem

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

If you are not the original author (lipalath-ms) and believe this issue is not stale, please comment with /bot not-stale and I will not close it.