Skip to content

Conversation

@steveharter
Copy link
Contributor

Adds "keyed" and the name of the key type to the message to help with diagnostics.

Fixes #112702

@steveharter steveharter added enhancement Product code improvement that does NOT require public API changes/additions area-Extensions-DependencyInjection labels Apr 17, 2025
@steveharter steveharter added this to the 10.0.0 milestone Apr 17, 2025
@steveharter steveharter requested a review from tarekgh April 17, 2025 18:44
@steveharter steveharter self-assigned this Apr 17, 2025
Copilot AI review requested due to automatic review settings April 17, 2025 18:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • src/libraries/Microsoft.Extensions.DependencyInjection/src/Resources/Strings.resx: Language not supported

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection
See info in area-owners.md if you want to be subscribed.

<value>KeyedService.AnyKey cannot be used to resolve a single service.</value>
</data>
<data name="NoKeyedServiceRegistered" xml:space="preserve">
<value>No keyed service for type '{0}' using key type '{1}' has been registered.</value>
Copy link
Member

@stephentoub stephentoub Apr 17, 2025

Choose a reason for hiding this comment

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

We don't want to include a ToString()'d key, only its type? Seems like one of the most common types of keys is string, and that string value would be more useful than "System.String". Is it that we're concerned about leaking details in the error message?

Copy link
Contributor Author

@steveharter steveharter Apr 17, 2025

Choose a reason for hiding this comment

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

We typically don't show disclose (possible) user data, but type names are OK.

Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

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

modulo @stephentoub comment, LGTM.

@steveharter
Copy link
Contributor Author

/ba-g infra build timeouts

@steveharter steveharter merged commit 7d247dd into dotnet:main Apr 18, 2025
76 of 87 checks passed
@steveharter steveharter deleted the DiImproveMessage branch April 18, 2025 15:52
@github-actions github-actions bot locked and limited conversation to collaborators May 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Extensions-DependencyInjection enhancement Product code improvement that does NOT require public API changes/additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Imprecise exception message when resolving keyed services.

3 participants