Skip to content

Commit c53f7e4

Browse files
authored
Improve key service unsupported exception message (#53226)
1 parent cba3002 commit c53f7e4

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ internal static void EmitKeyedServiceParameterPreparation(this EndpointParameter
337337

338338
codeWriter.WriteLine("if (httpContext.RequestServices.GetService<IServiceProviderIsService>() is not IServiceProviderIsKeyedService)");
339339
codeWriter.StartBlock();
340-
codeWriter.WriteLine(@"throw new InvalidOperationException($""Unable to resolve {nameof(FromKeyedServicesAttribute)}. This service provider doesn't support keyed services."");");
340+
codeWriter.WriteLine(@"throw new InvalidOperationException($""Unable to resolve service referenced by {nameof(FromKeyedServicesAttribute)}. The service provider doesn't support keyed services."");");
341341
codeWriter.EndBlock();
342342

343343
var assigningCode = endpointParameter.IsOptional ?

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ private static Expression CreateArgument(ParameterInfo parameter, RequestDelegat
790790
{
791791
if (factoryContext.ServiceProviderIsService is not IServiceProviderIsKeyedService)
792792
{
793-
throw new InvalidOperationException($"Unable to resolve {nameof(FromKeyedServicesAttribute)}. This service provider doesn't support keyed services.");
793+
throw new InvalidOperationException($"Unable to resolve service referenced by {nameof(FromKeyedServicesAttribute)}. The service provider doesn't support keyed services.");
794794
}
795795
var key = keyedServicesAttribute.Key;
796796
return BindParameterFromKeyedService(parameter, key, factoryContext);

src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.KeyServices.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ public async Task ThrowsIfDiContainerDoesNotSupportKeyedServices()
214214
if (!IsGeneratorEnabled)
215215
{
216216
var runtimeException = Assert.Throws<InvalidOperationException>(() => GetEndpointFromCompilation(compilation, serviceProvider: serviceProvider));
217-
Assert.Equal("Unable to resolve FromKeyedServicesAttribute. This service provider doesn't support keyed services.", runtimeException.Message);
217+
Assert.Equal("Unable to resolve service referenced by FromKeyedServicesAttribute. The service provider doesn't support keyed services.", runtimeException.Message);
218218
return;
219219
}
220220
var endpoint = GetEndpointFromCompilation(compilation, serviceProvider: serviceProvider);
221221

222222
var httpContext = CreateHttpContext(serviceProvider);
223223
var exception = await Assert.ThrowsAsync<InvalidOperationException>(async () => await endpoint.RequestDelegate(httpContext));
224-
Assert.Equal("Unable to resolve FromKeyedServicesAttribute. This service provider doesn't support keyed services.", exception.Message);
224+
Assert.Equal("Unable to resolve service referenced by FromKeyedServicesAttribute. The service provider doesn't support keyed services.", exception.Message);
225225
}
226226

227227
private class MockServiceProvider : IServiceProvider, ISupportRequiredService

src/SignalR/server/Core/src/Internal/HubMethodDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public HubMethodDescriptor(ObjectMethodExecutor methodExecutor, IServiceProvider
110110
}
111111
else
112112
{
113-
throw new InvalidOperationException($"This service provider doesn't support keyed services.");
113+
throw new InvalidOperationException($"Unable to resolve service referenced by {nameof(FromKeyedServicesAttribute)}. The service provider doesn't support keyed services.");
114114
}
115115
}
116116

0 commit comments

Comments
 (0)