Skip to content

Commit 5872814

Browse files
Allow null arguments from HubConnection (#11241)
1 parent f652c22 commit 5872814

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ private Dictionary<string, object> PackageStreamingParams(ConnectionState connec
627627

628628
for (var i = 0; i < args.Length; i++)
629629
{
630-
if (ReflectionHelper.IsStreamingType(args[i].GetType()))
630+
if (args[i] != null && ReflectionHelper.IsStreamingType(args[i].GetType()))
631631
{
632632
if (readers == null)
633633
{

src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,34 @@ public async Task CanSendAndReceiveMessage(string protocolName, HttpTransportTyp
138138
}
139139
}
140140

141+
[Theory]
142+
[MemberData(nameof(HubProtocolsList))]
143+
public async Task CanSendNull(string protocolName)
144+
{
145+
var protocol = HubProtocols[protocolName];
146+
using (StartServer<Startup>(out var server))
147+
{
148+
var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.LongPolling, protocol, LoggerFactory);
149+
try
150+
{
151+
await connection.StartAsync().OrTimeout();
152+
153+
var result = await connection.InvokeAsync<string>(nameof(TestHub.Echo), null).OrTimeout();
154+
155+
Assert.Null(result);
156+
}
157+
catch (Exception ex)
158+
{
159+
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
160+
throw;
161+
}
162+
finally
163+
{
164+
await connection.DisposeAsync().OrTimeout();
165+
}
166+
}
167+
}
168+
141169
[Theory]
142170
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
143171
[LogLevel(LogLevel.Trace)]

0 commit comments

Comments
 (0)