Skip to content

[Breaking change]: Throw when resolving on a disposed service provider #26783

Closed
@maryamariyan

Description

@maryamariyan

Description

Resolving Services after ServiceProvider is Disposed should throw with ObjectDisposedException.

PR: dotnet/runtime#45116

Version

.NET 6 RC 1

Previous behavior

Prior to the new change, if the application when through the rare case of resolving a service after service provider is disposed, it would lead to deadlock.

New behavior

Rather than deadlock, it will throw ObjectDisposedException.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.

Reason for change

To unblock the deadlock scenario.

Recommended action

N/A

Feature area

C#, Core .NET libraries, Extensions

Affected APIs

IServiceProvider GetService or GetRequiredService with Dispose usages in combination.

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 6Issues and PRs for the .NET 6 releasebreaking-changeIndicates a .NET Core breaking changesource incompatibleSource code may encounter a breaking change in behavior when targeting the new version.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions