Better exception for Generic methods on Hub (#15388)
This commit is contained in:
parent
814a37548b
commit
0d02d7a705
|
|
@ -547,6 +547,11 @@ namespace Microsoft.AspNetCore.SignalR.Internal
|
|||
|
||||
foreach (var methodInfo in HubReflectionHelper.GetHubMethods(hubType))
|
||||
{
|
||||
if (methodInfo.IsGenericMethod)
|
||||
{
|
||||
throw new NotSupportedException($"Method '{methodInfo.Name}' is a generic method which is not supported on a Hub.");
|
||||
}
|
||||
|
||||
var methodName =
|
||||
methodInfo.GetCustomAttribute<HubMethodNameAttribute>()?.Name ??
|
||||
methodInfo.Name;
|
||||
|
|
|
|||
|
|
@ -569,6 +569,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
}
|
||||
}
|
||||
|
||||
public class GenericMethodHub : Hub
|
||||
{
|
||||
public void GenericMethod<T>()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class DisposeTrackingHub : TestHub
|
||||
{
|
||||
private readonly TrackDispose _trackDispose;
|
||||
|
|
|
|||
|
|
@ -1327,6 +1327,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CannotHaveGenericMethodOnHub()
|
||||
{
|
||||
using (StartVerifiableLog())
|
||||
{
|
||||
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
|
||||
|
||||
var exception = Assert.Throws<NotSupportedException>(() => serviceProvider.GetService<HubConnectionHandler<GenericMethodHub>>());
|
||||
|
||||
Assert.Equal("Method 'GenericMethod' is a generic method which is not supported on a Hub.", exception.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(HubTypes))]
|
||||
public async Task BroadcastHubMethodSendsToAllClients(Type hubType)
|
||||
|
|
|
|||
Loading…
Reference in New Issue