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.

Version introduced

6.0 RC 1

Previous behavior

Previously, in the rare case that an application resolved a service after the service provider was disposed, it led to a deadlock.

New behavior

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.

Affected APIs