azure-functions-host
azure-functions-host copied to clipboard
Container is disposed and should not be used exception after .NET 6 upgrade
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);
});
}
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?
Sorry for the delayed response, we must have missed this issue. Are you still seeing the same problem with all the latest packages?
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.