-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
In ServiceProvider, when attempting to resolve a keyed service for which you haven't registered that key, you get an error message (SR.NoServiceRegistered) saying "No service for type '{type}' has been registered.":
runtime/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceProvider.cs
Lines 129 to 133 in 5587e2f
| object? service = GetKeyedService(serviceType, serviceKey, serviceProviderEngineScope); | |
| if (service == null) | |
| { | |
| throw new InvalidOperationException(SR.Format(SR.NoServiceRegistered, serviceType)); | |
| } |
When serviceKey != null, the error message should mention something along the lines of "for the serviceKey".
I understand that the key can't necessarily be displayed, but just mentioning that would help solve the issue causing the exception.
Having the message conditional on serviceKey being null or not adds a bit a processing, but considering that it's already on a failing path, while throwing an exception, I think it's acceptable..