Resolving disposed ServiceProvider throws exception
When a service is resolved after the service provider has been disposed, the affected methods now throw an ObjectDisposedException instead of causing a deadlock.
6.0 RC 1
Previously, in the rare case that an application resolved a service after the service provider was disposed, it led to a deadlock.
Starting in .NET 6, an ObjectDisposedException is thrown when a service is resolved after the service provider has been disposed, and there's no deadlock.
Type of breaking change
This change can affect source compatibility.
Reason for change
This change was introduced to fix the deadlock scenario.
Catch ObjectDisposedException when calling any of the affected APIs.
- Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider, Type)
Submit and view feedback for