-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception on IHostApplicationLifetime.StopApplication() #49473
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue Detailsxxx type only implements IAsyncDisposable. Use DisposeAsync to dispose the container. is thrown on calling
|
Can you show the stack trace? Where are disposing the host from? |
|
In the CrawlService, are you making a custom service scope and calling Dispose instead of DisposeAsync? Why? |
Hmm, looking at that stack - it's not exactly what I saw initially, I changed the code significantly since then but didn't save the stack trace (shame on me) and now I just tried to reproduce it. Initially, it was failing on StopApplication(), although it's on the last line in that method... Anyway, to answer your question - I don't call Dispose explicitly, but I do |
Unfortunately, the workaround for this is a big ugly: public static class ServiceScopeExtensions
{
public static AsyncServiceScope CreateAsyncServiceScope(this IServiceProvider serviceProvider)
{
return new AsyncServiceScope(serviceProvider.CreateScope());
}
}
public struct AsyncServiceScope : IServiceScope, IAsyncDisposable
{
private readonly IServiceScope _serviceScope;
public AsyncServiceScope(IServiceScope serviceScope)
{
_serviceScope = serviceScope;
}
public IServiceProvider ServiceProvider => _serviceScope.ServiceProvider;
public void Dispose()
{
_serviceScope.Dispose();
}
public ValueTask DisposeAsync()
{
if (_serviceScope is IAsyncDisposable ad)
{
return ad.DisposeAsync();
}
_serviceScope.Dispose();
return ValueTask.CompletedTask;
}
} Then you can change your code to do this: await using var scope = _serviceProvider.CreateAsyncServiceScope(); |
See #43970 for more information. |
Closing this one |
xxx type only implements IAsyncDisposable. Use DisposeAsync to dispose the container. is thrown on calling
IHostApplicationLifetime.StopApplication()
if there's a service in the container that implementsIAsyncDisposable
but notIDisposable
. Any ideas how to deal with it (other than callingDisposeAsync().GetAwaiter().GetResult();
fromDispose()
, which may lead to a deadlock)? I suspect havingIHostApplicationLifetime.StopApplicationAsync()
could help, but it doesn't exist.The text was updated successfully, but these errors were encountered: