Skip to content

Conversation

@ReubenBond
Copy link
Contributor

@ReubenBond ReubenBond commented Feb 13, 2024

Fix ServiceDescriptor access when Keyed Services are present

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Fixes the use of ServiceDescriptor for containers which have keyed services present. This can be an issue on .NET 8.0 and has been reported by some users of the library here: #2604

Description

The issue is caused by unconditional access to ServiceDescriptor.ImplementationType and the fix is to first check whether ServiceDescriptor.ServiceKey is set. If it is, we can safely ignore that descriptor.

For more information on keyed services, see the dotnet/runtime thread here: dotnet/runtime#64427 and the PR here: dotnet/runtime#87183.

Fixes #2604

Copy link
Collaborator

@jmprieur jmprieur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ReubenBond

LGTM

@adityamandaleeka
Copy link

Can this be merged now?

@onionhammer
Copy link

This seems like something that should be fixed sooner rather than later...

Copy link
Collaborator

@jennyf19 jennyf19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:
Thanks for the contribution @ReubenBond

@jennyf19 jennyf19 added this to the 2.17.1 milestone Feb 25, 2024
@jennyf19 jennyf19 merged commit b6cc9eb into AzureAD:master Feb 25, 2024
@vijuhe
Copy link

vijuhe commented Feb 27, 2024

Can this be released now or very soon at least? There is still one open feature in the release 2.17.1. Can the release be done without it?

@jennyf19
Copy link
Collaborator

@vijuhe we are testing the 2.17.1. It should be out later today PST.

@jennyf19
Copy link
Collaborator

Included in 2.17.1 Thanks @ReubenBond

@ReubenBond ReubenBond deleted the rebond/fix-keyed-di branch March 12, 2024 15:19
This was referenced Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET 8 WebApi throws InvalidOperationException when keyed Services are registered before MS Identity Services are registered

7 participants