From 5872814a64dcb25bdd447fe8a905fb331d1018e9 Mon Sep 17 00:00:00 2001 From: Brennan Date: Fri, 14 Jun 2019 20:37:13 -0700 Subject: [PATCH] Allow null arguments from HubConnection (#11241) --- .../csharp/Client.Core/src/HubConnection.cs | 2 +- .../FunctionalTests/HubConnectionTests.cs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs b/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs index f53973da1f..19eaba4d0a 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs +++ b/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs @@ -627,7 +627,7 @@ namespace Microsoft.AspNetCore.SignalR.Client for (var i = 0; i < args.Length; i++) { - if (ReflectionHelper.IsStreamingType(args[i].GetType())) + if (args[i] != null && ReflectionHelper.IsStreamingType(args[i].GetType())) { if (readers == null) { diff --git a/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs b/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs index 82e95d78c2..369adb8895 100644 --- a/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs +++ b/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs @@ -138,6 +138,34 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests } } + [Theory] + [MemberData(nameof(HubProtocolsList))] + public async Task CanSendNull(string protocolName) + { + var protocol = HubProtocols[protocolName]; + using (StartServer(out var server)) + { + var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.LongPolling, protocol, LoggerFactory); + try + { + await connection.StartAsync().OrTimeout(); + + var result = await connection.InvokeAsync(nameof(TestHub.Echo), null).OrTimeout(); + + Assert.Null(result); + } + catch (Exception ex) + { + LoggerFactory.CreateLogger().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName); + throw; + } + finally + { + await connection.DisposeAsync().OrTimeout(); + } + } + } + [Theory] [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] [LogLevel(LogLevel.Trace)]