From 1867750ec997911a64a0a02c0eaf82cc8a2ba4ae Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 13 Aug 2020 22:26:03 -0700 Subject: [PATCH] Add nullable annotations to SignalR.Common, SignalR.Core and Http.Connections (#24764) * Add nullable annotations to SignalR.Common, SignalR.Core and Http.Connections Contributes to https://github.com/dotnet/aspnetcore/issues/5680 * Changes per PR comments. Also add nullability to hub protocols --- .../src/BaseConnectionContext.cs | 4 +- .../src/ConnectionContext.cs | 2 +- .../src/DefaultConnectionContext.cs | 6 +- .../src/Features/IConnectionIdFeature.cs | 2 +- .../src/Features/IConnectionItemsFeature.cs | 2 +- .../Features/IConnectionTransportFeature.cs | 2 +- .../ObjectMethodExecutor/AwaitableInfo.cs | 2 + .../CoercedAwaitableInfo.cs | 2 + .../ObjectMethodExecutor.cs | 2 + .../ObjectMethodExecutorAwaitable.cs | 2 + .../ObjectMethodExecutorFSharpSupport.cs | 2 + ...onnectionEndpointRouteBuilderExtensions.cs | 2 +- .../src/HttpConnectionContextExtensions.cs | 2 +- .../src/Internal/ConnectionLogScope.cs | 2 + .../src/Internal/HttpConnectionContext.cs | 2 + .../Internal/HttpConnectionDispatcher.Log.cs | 32 ++--- .../src/Internal/HttpConnectionDispatcher.cs | 2 + .../src/Internal/HttpConnectionManager.Log.cs | 16 +-- .../src/Internal/HttpConnectionManager.cs | 3 +- .../Internal/HttpConnectionsEventSource.cs | 2 + .../Transports/LongPollingServerTransport.cs | 14 +-- .../ServerSentEventsServerTransport.cs | 6 +- .../WebSocketsServerTransport.Log.cs | 32 ++--- .../Transports/WebSocketsServerTransport.cs | 2 +- ...crosoft.AspNetCore.Http.Connections.csproj | 1 + .../Http.Connections/src/WebSocketOptions.cs | 2 +- ...t.AspNetCore.SignalR.Protocols.Json.csproj | 1 + .../src/Protocol/JsonHubProtocol.cs | 2 + .../src/MessagePackHubProtocolOptions.cs | 3 +- ...tCore.SignalR.Protocols.MessagePack.csproj | 1 + .../src/Protocol/MessagePackHubProtocol.cs | 2 + ...re.SignalR.Protocols.NewtonsoftJson.csproj | 3 +- .../src/Protocol/NewtonsoftJsonHubProtocol.cs | 2 + .../common/Shared/AsyncEnumerableAdapters.cs | 2 + .../common/Shared/MemoryBufferWriter.cs | 2 + src/SignalR/common/Shared/PipeWriterStream.cs | 2 + src/SignalR/common/Shared/ReflectionHelper.cs | 2 + .../common/Shared/ReusableUtf8JsonWriter.cs | 2 + .../common/Shared/SystemTextJsonExtensions.cs | 4 +- src/SignalR/common/Shared/TimerAwaitable.cs | 8 +- .../common/Shared/Utf8BufferTextReader.cs | 4 +- .../common/Shared/Utf8BufferTextWriter.cs | 2 + .../common/SignalR.Common/src/HubException.cs | 4 +- ...Microsoft.AspNetCore.SignalR.Common.csproj | 3 +- .../src/Protocol/CloseMessage.cs | 6 +- .../src/Protocol/CompletionMessage.cs | 7 +- .../src/Protocol/HandshakeProtocol.cs | 9 +- .../src/Protocol/HandshakeRequestMessage.cs | 2 +- .../src/Protocol/HandshakeResponseMessage.cs | 4 +- .../src/Protocol/HubInvocationMessage.cs | 6 +- .../Protocol/HubMethodInvocationMessage.cs | 18 +-- .../src/Protocol/IHubProtocol.cs | 3 +- .../src/Protocol/StreamItemMessage.cs | 4 +- .../server/Core/src/ClientProxyExtensions.cs | 20 ++-- .../Core/src/DefaultHubLifetimeManager.cs | 52 ++++---- .../server/Core/src/DefaultUserIdProvider.cs | 6 +- src/SignalR/server/Core/src/DynamicHub.cs | 4 +- src/SignalR/server/Core/src/Hub.cs | 8 +- .../server/Core/src/HubCallerContext.cs | 6 +- .../Core/src/HubConnectionContext.Log.cs | 97 +++++++++++++++ .../server/Core/src/HubConnectionContext.cs | 112 +++--------------- .../Core/src/HubConnectionContextOptions.cs | 2 +- .../server/Core/src/HubConnectionHandler.cs | 18 +-- .../server/Core/src/HubConnectionStore.cs | 4 +- .../server/Core/src/HubInvocationContext.cs | 10 +- .../server/Core/src/HubLifetimeManager.cs | 18 +-- src/SignalR/server/Core/src/HubOptions.cs | 4 +- .../server/Core/src/HubOptionsSetup`T.cs | 3 +- src/SignalR/server/Core/src/Hub`T.cs | 4 +- src/SignalR/server/Core/src/IClientProxy.cs | 2 +- src/SignalR/server/Core/src/IHubFilter.cs | 6 +- .../server/Core/src/IHubProtocolResolver.cs | 2 +- .../server/Core/src/IUserIdProvider.cs | 6 +- .../src/Internal/DefaultHubCallerContext.cs | 6 +- .../src/Internal/DefaultHubDispatcher.Log.cs | 2 + .../Core/src/Internal/DefaultHubDispatcher.cs | 2 + .../Internal/DefaultHubProtocolResolver.cs | 6 +- .../Core/src/Internal/DynamicClientProxy.cs | 4 +- .../server/Core/src/Internal/HubDispatcher.cs | 2 +- .../Core/src/Internal/HubFilterFactory.cs | 6 +- .../server/Core/src/Internal/HubGroupList.cs | 8 +- .../Core/src/Internal/HubMethodDescriptor.cs | 2 + .../Core/src/Internal/HubReflectionHelper.cs | 2 +- .../server/Core/src/Internal/Proxies.cs | 18 +-- .../Core/src/Internal/TypedClientBuilder.cs | 2 + .../Microsoft.AspNetCore.SignalR.Core.csproj | 1 + .../server/Core/src/SerializedHubMessage.cs | 4 +- src/SignalR/server/Core/src/StreamTracker.cs | 2 + 88 files changed, 388 insertions(+), 319 deletions(-) create mode 100644 src/SignalR/server/Core/src/HubConnectionContext.Log.cs diff --git a/src/Servers/Connections.Abstractions/src/BaseConnectionContext.cs b/src/Servers/Connections.Abstractions/src/BaseConnectionContext.cs index dcaf110cde..2dbf9340b1 100644 --- a/src/Servers/Connections.Abstractions/src/BaseConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/BaseConnectionContext.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Connections /// /// Gets or sets a unique identifier to represent this connection in trace logs. /// - public abstract string? ConnectionId { get; set; } + public abstract string ConnectionId { get; set; } /// /// Gets the collection of features provided by the server and middleware available on this connection. @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Connections /// /// Gets or sets a key/value collection that can be used to share data within the scope of this connection. /// - public abstract IDictionary? Items { get; set; } + public abstract IDictionary Items { get; set; } /// /// Triggered when the client connection is closed. diff --git a/src/Servers/Connections.Abstractions/src/ConnectionContext.cs b/src/Servers/Connections.Abstractions/src/ConnectionContext.cs index ffd4136ef8..02b291c2c8 100644 --- a/src/Servers/Connections.Abstractions/src/ConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/ConnectionContext.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Connections /// /// Gets or sets the that can be used to read or write data on this connection. /// - public abstract IDuplexPipe? Transport { get; set; } + public abstract IDuplexPipe Transport { get; set; } /// /// Aborts the underlying connection. diff --git a/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs b/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs index 9ad2c62e8a..62ecdf4e4b 100644 --- a/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs @@ -55,17 +55,17 @@ namespace Microsoft.AspNetCore.Connections Application = application; } - public override string? ConnectionId { get; set; } + public override string ConnectionId { get; set; } public override IFeatureCollection Features { get; } public ClaimsPrincipal? User { get; set; } - public override IDictionary? Items { get; set; } = new ConnectionItems(); + public override IDictionary Items { get; set; } = new ConnectionItems(); public IDuplexPipe? Application { get; set; } - public override IDuplexPipe? Transport { get; set; } + public override IDuplexPipe Transport { get; set; } = default!; public override CancellationToken ConnectionClosed { get; set; } public override EndPoint? LocalEndPoint { get; set; } diff --git a/src/Servers/Connections.Abstractions/src/Features/IConnectionIdFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionIdFeature.cs index 8068e0cd6c..7058a3476f 100644 --- a/src/Servers/Connections.Abstractions/src/Features/IConnectionIdFeature.cs +++ b/src/Servers/Connections.Abstractions/src/Features/IConnectionIdFeature.cs @@ -5,6 +5,6 @@ namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionIdFeature { - string? ConnectionId { get; set; } + string ConnectionId { get; set; } } } diff --git a/src/Servers/Connections.Abstractions/src/Features/IConnectionItemsFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionItemsFeature.cs index e0e8e43703..038383e65e 100644 --- a/src/Servers/Connections.Abstractions/src/Features/IConnectionItemsFeature.cs +++ b/src/Servers/Connections.Abstractions/src/Features/IConnectionItemsFeature.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionItemsFeature { - IDictionary? Items { get; set; } + IDictionary Items { get; set; } } } diff --git a/src/Servers/Connections.Abstractions/src/Features/IConnectionTransportFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionTransportFeature.cs index 7f4fd4f9d6..deba5a8c1e 100644 --- a/src/Servers/Connections.Abstractions/src/Features/IConnectionTransportFeature.cs +++ b/src/Servers/Connections.Abstractions/src/Features/IConnectionTransportFeature.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionTransportFeature { - IDuplexPipe? Transport { get; set; } + IDuplexPipe Transport { get; set; } } } diff --git a/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs b/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs index ef0daf4186..f25736e6cc 100644 --- a/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs +++ b/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Linq; using System.Reflection; diff --git a/src/Shared/ObjectMethodExecutor/CoercedAwaitableInfo.cs b/src/Shared/ObjectMethodExecutor/CoercedAwaitableInfo.cs index 11bf32f7bc..b27c66c72d 100644 --- a/src/Shared/ObjectMethodExecutor/CoercedAwaitableInfo.cs +++ b/src/Shared/ObjectMethodExecutor/CoercedAwaitableInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Linq.Expressions; diff --git a/src/Shared/ObjectMethodExecutor/ObjectMethodExecutor.cs b/src/Shared/ObjectMethodExecutor/ObjectMethodExecutor.cs index f8e5b70f0d..084f7f0aad 100644 --- a/src/Shared/ObjectMethodExecutor/ObjectMethodExecutor.cs +++ b/src/Shared/ObjectMethodExecutor/ObjectMethodExecutor.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Collections.Generic; using System.Linq.Expressions; diff --git a/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorAwaitable.cs b/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorAwaitable.cs index 02ffd7c4ce..a4183b81ff 100644 --- a/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorAwaitable.cs +++ b/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorAwaitable.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Runtime.CompilerServices; diff --git a/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorFSharpSupport.cs b/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorFSharpSupport.cs index 2198c0ce45..11ab59c42b 100644 --- a/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorFSharpSupport.cs +++ b/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorFSharpSupport.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Linq; using System.Linq.Expressions; diff --git a/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs b/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs index 97ba2b3c0e..d9a34035a9 100644 --- a/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs +++ b/src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Builder /// The route pattern. /// A callback to configure dispatcher options. /// An for endpoints associated with the connections. - public static ConnectionEndpointRouteBuilder MapConnectionHandler(this IEndpointRouteBuilder endpoints, string pattern, Action configureOptions) where TConnectionHandler : ConnectionHandler + public static ConnectionEndpointRouteBuilder MapConnectionHandler(this IEndpointRouteBuilder endpoints, string pattern, Action? configureOptions) where TConnectionHandler : ConnectionHandler { var options = new HttpConnectionDispatcherOptions(); configureOptions?.Invoke(options); diff --git a/src/SignalR/common/Http.Connections/src/HttpConnectionContextExtensions.cs b/src/SignalR/common/Http.Connections/src/HttpConnectionContextExtensions.cs index b2f8a10cd1..2b31aee59f 100644 --- a/src/SignalR/common/Http.Connections/src/HttpConnectionContextExtensions.cs +++ b/src/SignalR/common/Http.Connections/src/HttpConnectionContextExtensions.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Http.Connections /// SignalR connections can run on top of HTTP transports like WebSockets or Long Polling, or other non-HTTP transports. As a result, /// this method can sometimes return depending on the configuration of your application. /// - public static HttpContext GetHttpContext(this ConnectionContext connection) + public static HttpContext? GetHttpContext(this ConnectionContext connection) { return connection.Features.Get()?.HttpContext; } diff --git a/src/SignalR/common/Http.Connections/src/Internal/ConnectionLogScope.cs b/src/SignalR/common/Http.Connections/src/Internal/ConnectionLogScope.cs index f31a73014d..710d563365 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/ConnectionLogScope.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/ConnectionLogScope.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Collections; using System.Collections.Generic; diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs index 5958c7ef92..63f97c300e 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.Log.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.Log.cs index 5f5158a1fb..382c0d38f2 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.Log.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.Log.cs @@ -10,52 +10,52 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal { internal static class Log { - private static readonly Action _connectionDisposed = + private static readonly Action _connectionDisposed = LoggerMessage.Define(LogLevel.Debug, new EventId(1, "ConnectionDisposed"), "Connection {TransportConnectionId} was disposed."); - private static readonly Action _connectionAlreadyActive = + private static readonly Action _connectionAlreadyActive = LoggerMessage.Define(LogLevel.Debug, new EventId(2, "ConnectionAlreadyActive"), "Connection {TransportConnectionId} is already active via {RequestId}."); - private static readonly Action _pollCanceled = + private static readonly Action _pollCanceled = LoggerMessage.Define(LogLevel.Trace, new EventId(3, "PollCanceled"), "Previous poll canceled for {TransportConnectionId} on {RequestId}."); - private static readonly Action _establishedConnection = + private static readonly Action _establishedConnection = LoggerMessage.Define(LogLevel.Debug, new EventId(4, "EstablishedConnection"), "Establishing new connection."); - private static readonly Action _resumingConnection = + private static readonly Action _resumingConnection = LoggerMessage.Define(LogLevel.Debug, new EventId(5, "ResumingConnection"), "Resuming existing connection."); - private static readonly Action _receivedBytes = + private static readonly Action _receivedBytes = LoggerMessage.Define(LogLevel.Trace, new EventId(6, "ReceivedBytes"), "Received {Count} bytes."); - private static readonly Action _transportNotSupported = + private static readonly Action _transportNotSupported = LoggerMessage.Define(LogLevel.Debug, new EventId(7, "TransportNotSupported"), "{TransportType} transport not supported by this connection handler."); - private static readonly Action _cannotChangeTransport = + private static readonly Action _cannotChangeTransport = LoggerMessage.Define(LogLevel.Debug, new EventId(8, "CannotChangeTransport"), "Cannot change transports mid-connection; currently using {TransportType}, requesting {RequestedTransport}."); - private static readonly Action _postNotallowedForWebsockets = + private static readonly Action _postNotallowedForWebsockets = LoggerMessage.Define(LogLevel.Debug, new EventId(9, "PostNotAllowedForWebSockets"), "POST requests are not allowed for websocket connections."); - private static readonly Action _negotiationRequest = + private static readonly Action _negotiationRequest = LoggerMessage.Define(LogLevel.Debug, new EventId(10, "NegotiationRequest"), "Sending negotiation response."); - private static readonly Action _receivedDeleteRequestForUnsupportedTransport = + private static readonly Action _receivedDeleteRequestForUnsupportedTransport = LoggerMessage.Define(LogLevel.Trace, new EventId(11, "ReceivedDeleteRequestForUnsupportedTransport"), "Received DELETE request for unsupported transport: {TransportType}."); - private static readonly Action _terminatingConnection = + private static readonly Action _terminatingConnection = LoggerMessage.Define(LogLevel.Trace, new EventId(12, "TerminatingConection"), "Terminating Long Polling connection due to a DELETE request."); - private static readonly Action _connectionDisposedWhileWriteInProgress = + private static readonly Action _connectionDisposedWhileWriteInProgress = LoggerMessage.Define(LogLevel.Debug, new EventId(13, "ConnectionDisposedWhileWriteInProgress"), "Connection {TransportConnectionId} was disposed while a write was in progress."); - private static readonly Action _failedToReadHttpRequestBody = + private static readonly Action _failedToReadHttpRequestBody = LoggerMessage.Define(LogLevel.Debug, new EventId(14, "FailedToReadHttpRequestBody"), "Connection {TransportConnectionId} failed to read the HTTP request body."); - private static readonly Action _negotiateProtocolVersionMismatch = + private static readonly Action _negotiateProtocolVersionMismatch = LoggerMessage.Define(LogLevel.Debug, new EventId(15, "NegotiateProtocolVersionMismatch"), "The client requested version '{clientProtocolVersion}', but the server does not support this version."); - private static readonly Action _invalidNegotiateProtocolVersion = + private static readonly Action _invalidNegotiateProtocolVersion = LoggerMessage.Define(LogLevel.Debug, new EventId(16, "InvalidNegotiateProtocolVersion"), "The client requested an invalid protocol version '{queryStringVersionValue}'"); public static void ConnectionDisposed(ILogger logger, string connectionId) diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs index fab15305ce..d20503d63e 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Buffers; using System.Collections.Generic; diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionManager.Log.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionManager.Log.cs index 2fa9d21885..6b691775d5 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionManager.Log.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionManager.Log.cs @@ -10,32 +10,32 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal { private static class Log { - private static readonly Action _createdNewConnection = + private static readonly Action _createdNewConnection = LoggerMessage.Define(LogLevel.Debug, new EventId(1, "CreatedNewConnection"), "New connection {TransportConnectionId} created."); - private static readonly Action _removedConnection = + private static readonly Action _removedConnection = LoggerMessage.Define(LogLevel.Debug, new EventId(2, "RemovedConnection"), "Removing connection {TransportConnectionId} from the list of connections."); - private static readonly Action _failedDispose = + private static readonly Action _failedDispose = LoggerMessage.Define(LogLevel.Error, new EventId(3, "FailedDispose"), "Failed disposing connection {TransportConnectionId}."); - private static readonly Action _connectionReset = + private static readonly Action _connectionReset = LoggerMessage.Define(LogLevel.Trace, new EventId(4, "ConnectionReset"), "Connection {TransportConnectionId} was reset."); - private static readonly Action _connectionTimedOut = + private static readonly Action _connectionTimedOut = LoggerMessage.Define(LogLevel.Trace, new EventId(5, "ConnectionTimedOut"), "Connection {TransportConnectionId} timed out."); // 6, ScanningConnections - removed - private static readonly Action _scanningConnectionsFailed = + private static readonly Action _scanningConnectionsFailed = LoggerMessage.Define(LogLevel.Error, new EventId(7, "ScanningConnectionsFailed"), "Scanning connections failed."); // 8, ScannedConnections - removed - private static readonly Action _heartbeatStarted = + private static readonly Action _heartbeatStarted = LoggerMessage.Define(LogLevel.Trace, new EventId(9, "HeartBeatStarted"), "Starting connection heartbeat."); - private static readonly Action _heartbeatEnded = + private static readonly Action _heartbeatEnded = LoggerMessage.Define(LogLevel.Trace, new EventId(10, "HeartBeatEnded"), "Ending connection heartbeat."); public static void CreatedNewConnection(ILogger logger, string connectionId) diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionManager.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionManager.cs index 2712b5d7cf..84f62abdc0 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionManager.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionManager.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.IO.Pipelines; using System.Net.WebSockets; @@ -50,7 +51,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal _ = ExecuteTimerLoop(); } - internal bool TryGetConnection(string id, out HttpConnectionContext connection) + internal bool TryGetConnection(string id, [NotNullWhen(true)] out HttpConnectionContext? connection) { connection = null; diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionsEventSource.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionsEventSource.cs index c07577b908..acbf2354f8 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionsEventSource.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionsEventSource.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System.Diagnostics.Tracing; using System.Threading; using Microsoft.Extensions.Internal; diff --git a/src/SignalR/common/Http.Connections/src/Internal/Transports/LongPollingServerTransport.cs b/src/SignalR/common/Http.Connections/src/Internal/Transports/LongPollingServerTransport.cs index 8ecf395276..3c3af9accb 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/Transports/LongPollingServerTransport.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/Transports/LongPollingServerTransport.cs @@ -16,13 +16,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports private readonly PipeReader _application; private readonly ILogger _logger; private readonly CancellationToken _timeoutToken; - private readonly HttpConnectionContext _connection; + private readonly HttpConnectionContext? _connection; public LongPollingServerTransport(CancellationToken timeoutToken, PipeReader application, ILoggerFactory loggerFactory) : this(timeoutToken, application, loggerFactory, connection: null) { } - public LongPollingServerTransport(CancellationToken timeoutToken, PipeReader application, ILoggerFactory loggerFactory, HttpConnectionContext connection) + public LongPollingServerTransport(CancellationToken timeoutToken, PipeReader application, ILoggerFactory loggerFactory, HttpConnectionContext? connection) { _timeoutToken = timeoutToken; _application = application; @@ -117,19 +117,19 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports private static class Log { - private static readonly Action _longPolling204 = + private static readonly Action _longPolling204 = LoggerMessage.Define(LogLevel.Debug, new EventId(1, "LongPolling204"), "Terminating Long Polling connection by sending 204 response."); - private static readonly Action _pollTimedOut = + private static readonly Action _pollTimedOut = LoggerMessage.Define(LogLevel.Debug, new EventId(2, "PollTimedOut"), "Poll request timed out. Sending 200 response to connection."); - private static readonly Action _longPollingWritingMessage = + private static readonly Action _longPollingWritingMessage = LoggerMessage.Define(LogLevel.Trace, new EventId(3, "LongPollingWritingMessage"), "Writing a {Count} byte message to connection."); - private static readonly Action _longPollingDisconnected = + private static readonly Action _longPollingDisconnected = LoggerMessage.Define(LogLevel.Debug, new EventId(4, "LongPollingDisconnected"), "Client disconnected from Long Polling endpoint for connection."); - private static readonly Action _longPollingTerminated = + private static readonly Action _longPollingTerminated = LoggerMessage.Define(LogLevel.Error, new EventId(5, "LongPollingTerminated"), "Long Polling transport was terminated due to an error on connection."); public static void LongPolling204(ILogger logger) diff --git a/src/SignalR/common/Http.Connections/src/Internal/Transports/ServerSentEventsServerTransport.cs b/src/SignalR/common/Http.Connections/src/Internal/Transports/ServerSentEventsServerTransport.cs index 450299bda3..b9bc12dbae 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/Transports/ServerSentEventsServerTransport.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/Transports/ServerSentEventsServerTransport.cs @@ -16,13 +16,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports private readonly PipeReader _application; private readonly string _connectionId; private readonly ILogger _logger; - private readonly HttpConnectionContext _connection; + private readonly HttpConnectionContext? _connection; public ServerSentEventsServerTransport(PipeReader application, string connectionId, ILoggerFactory loggerFactory) : this(application, connectionId, connection: null, loggerFactory) { } - public ServerSentEventsServerTransport(PipeReader application, string connectionId, HttpConnectionContext connection, ILoggerFactory loggerFactory) + public ServerSentEventsServerTransport(PipeReader application, string connectionId, HttpConnectionContext? connection, ILoggerFactory loggerFactory) { _application = application; _connectionId = connectionId; @@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports private static class Log { - private static readonly Action _sseWritingMessage = + private static readonly Action _sseWritingMessage = LoggerMessage.Define(LogLevel.Trace, new EventId(1, "SSEWritingMessage"), "Writing a {Count} byte message."); public static void SSEWritingMessage(ILogger logger, long count) diff --git a/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.Log.cs b/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.Log.cs index b847ef9984..5540d45cbd 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.Log.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.Log.cs @@ -11,51 +11,51 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports { private static class Log { - private static readonly Action _socketOpened = - LoggerMessage.Define(LogLevel.Debug, new EventId(1, "SocketOpened"), "Socket opened using Sub-Protocol: '{SubProtocol}'."); + private static readonly Action _socketOpened = + LoggerMessage.Define(LogLevel.Debug, new EventId(1, "SocketOpened"), "Socket opened using Sub-Protocol: '{SubProtocol}'."); - private static readonly Action _socketClosed = + private static readonly Action _socketClosed = LoggerMessage.Define(LogLevel.Debug, new EventId(2, "SocketClosed"), "Socket closed."); - private static readonly Action _clientClosed = + private static readonly Action _clientClosed = LoggerMessage.Define(LogLevel.Debug, new EventId(3, "ClientClosed"), "Client closed connection with status code '{Status}' ({Description}). Signaling end-of-input to application."); - private static readonly Action _waitingForSend = + private static readonly Action _waitingForSend = LoggerMessage.Define(LogLevel.Debug, new EventId(4, "WaitingForSend"), "Waiting for the application to finish sending data."); - private static readonly Action _failedSending = + private static readonly Action _failedSending = LoggerMessage.Define(LogLevel.Debug, new EventId(5, "FailedSending"), "Application failed during sending. Sending InternalServerError close frame."); - private static readonly Action _finishedSending = + private static readonly Action _finishedSending = LoggerMessage.Define(LogLevel.Debug, new EventId(6, "FinishedSending"), "Application finished sending. Sending close frame."); - private static readonly Action _waitingForClose = + private static readonly Action _waitingForClose = LoggerMessage.Define(LogLevel.Debug, new EventId(7, "WaitingForClose"), "Waiting for the client to close the socket."); - private static readonly Action _closeTimedOut = + private static readonly Action _closeTimedOut = LoggerMessage.Define(LogLevel.Debug, new EventId(8, "CloseTimedOut"), "Timed out waiting for client to send the close frame, aborting the connection."); - private static readonly Action _messageReceived = + private static readonly Action _messageReceived = LoggerMessage.Define(LogLevel.Trace, new EventId(9, "MessageReceived"), "Message received. Type: {MessageType}, size: {Size}, EndOfMessage: {EndOfMessage}."); - private static readonly Action _messageToApplication = + private static readonly Action _messageToApplication = LoggerMessage.Define(LogLevel.Trace, new EventId(10, "MessageToApplication"), "Passing message to application. Payload size: {Size}."); - private static readonly Action _sendPayload = + private static readonly Action _sendPayload = LoggerMessage.Define(LogLevel.Trace, new EventId(11, "SendPayload"), "Sending payload: {Size} bytes."); - private static readonly Action _errorWritingFrame = + private static readonly Action _errorWritingFrame = LoggerMessage.Define(LogLevel.Debug, new EventId(12, "ErrorWritingFrame"), "Error writing frame."); // 13, SendFailed - removed - private static readonly Action _closedPrematurely = + private static readonly Action _closedPrematurely = LoggerMessage.Define(LogLevel.Debug, new EventId(14, "ClosedPrematurely"), "Socket connection closed prematurely."); - private static readonly Action _closingWebSocketFailed = + private static readonly Action _closingWebSocketFailed = LoggerMessage.Define(LogLevel.Debug, new EventId(15, "ClosingWebSocketFailed"), "Closing webSocket failed."); - public static void SocketOpened(ILogger logger, string subProtocol) + public static void SocketOpened(ILogger logger, string? subProtocol) { _socketOpened(logger, subProtocol, null); } diff --git a/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.cs b/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.cs index a95041c48a..ef0be3ae85 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.cs @@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports private async Task StartSending(WebSocket socket) { - Exception error = null; + Exception? error = null; try { diff --git a/src/SignalR/common/Http.Connections/src/Microsoft.AspNetCore.Http.Connections.csproj b/src/SignalR/common/Http.Connections/src/Microsoft.AspNetCore.Http.Connections.csproj index dc545e48ba..a6224d57a4 100644 --- a/src/SignalR/common/Http.Connections/src/Microsoft.AspNetCore.Http.Connections.csproj +++ b/src/SignalR/common/Http.Connections/src/Microsoft.AspNetCore.Http.Connections.csproj @@ -5,6 +5,7 @@ $(DefaultNetCoreTargetFramework) true false + enable diff --git a/src/SignalR/common/Http.Connections/src/WebSocketOptions.cs b/src/SignalR/common/Http.Connections/src/WebSocketOptions.cs index 3fe27b35c4..8cac4f12f0 100644 --- a/src/SignalR/common/Http.Connections/src/WebSocketOptions.cs +++ b/src/SignalR/common/Http.Connections/src/WebSocketOptions.cs @@ -21,6 +21,6 @@ namespace Microsoft.AspNetCore.Http.Connections // WebSocketManager's list of sub protocols is an IList: // https://github.com/aspnet/HttpAbstractions/blob/a6bdb9b1ec6ed99978a508e71a7f131be7e4d9fb/src/Microsoft.AspNetCore.Http.Abstractions/WebSocketManager.cs#L23 // Unfortunately, IList does not implement IReadOnlyList :( - public Func, string> SubProtocolSelector { get; set; } + public Func, string>? SubProtocolSelector { get; set; } } } diff --git a/src/SignalR/common/Protocols.Json/src/Microsoft.AspNetCore.SignalR.Protocols.Json.csproj b/src/SignalR/common/Protocols.Json/src/Microsoft.AspNetCore.SignalR.Protocols.Json.csproj index 98865bf6c9..fa1317d365 100644 --- a/src/SignalR/common/Protocols.Json/src/Microsoft.AspNetCore.SignalR.Protocols.Json.csproj +++ b/src/SignalR/common/Protocols.Json/src/Microsoft.AspNetCore.SignalR.Protocols.Json.csproj @@ -7,6 +7,7 @@ true Microsoft.AspNetCore.SignalR true + enable diff --git a/src/SignalR/common/Protocols.Json/src/Protocol/JsonHubProtocol.cs b/src/SignalR/common/Protocols.Json/src/Protocol/JsonHubProtocol.cs index 45870709d8..b9438b57b1 100644 --- a/src/SignalR/common/Protocols.Json/src/Protocol/JsonHubProtocol.cs +++ b/src/SignalR/common/Protocols.Json/src/Protocol/JsonHubProtocol.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Buffers; using System.Collections.Generic; diff --git a/src/SignalR/common/Protocols.MessagePack/src/MessagePackHubProtocolOptions.cs b/src/SignalR/common/Protocols.MessagePack/src/MessagePackHubProtocolOptions.cs index bd2ad8f788..eec0355405 100644 --- a/src/SignalR/common/Protocols.MessagePack/src/MessagePackHubProtocolOptions.cs +++ b/src/SignalR/common/Protocols.MessagePack/src/MessagePackHubProtocolOptions.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; using MessagePack; using Microsoft.AspNetCore.SignalR.Protocol; @@ -9,7 +8,7 @@ namespace Microsoft.AspNetCore.SignalR { public class MessagePackHubProtocolOptions { - private MessagePackSerializerOptions _messagePackSerializerOptions; + private MessagePackSerializerOptions? _messagePackSerializerOptions; /// /// Gets or sets the used internally by the . diff --git a/src/SignalR/common/Protocols.MessagePack/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj b/src/SignalR/common/Protocols.MessagePack/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj index 1781a2fb16..65817ce39e 100644 --- a/src/SignalR/common/Protocols.MessagePack/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj +++ b/src/SignalR/common/Protocols.MessagePack/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj @@ -5,6 +5,7 @@ netstandard2.0 Microsoft.AspNetCore.SignalR true + enable diff --git a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs index d9a8ea817b..d4050d83d4 100644 --- a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs +++ b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Buffers; using System.Collections.Generic; diff --git a/src/SignalR/common/Protocols.NewtonsoftJson/src/Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson.csproj b/src/SignalR/common/Protocols.NewtonsoftJson/src/Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson.csproj index 1338f232b5..ee6a01dfbf 100644 --- a/src/SignalR/common/Protocols.NewtonsoftJson/src/Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson.csproj +++ b/src/SignalR/common/Protocols.NewtonsoftJson/src/Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson.csproj @@ -1,10 +1,11 @@ - + Implements the SignalR Hub Protocol using Newtonsoft.Json. netstandard2.0 Microsoft.AspNetCore.SignalR true + enable diff --git a/src/SignalR/common/Protocols.NewtonsoftJson/src/Protocol/NewtonsoftJsonHubProtocol.cs b/src/SignalR/common/Protocols.NewtonsoftJson/src/Protocol/NewtonsoftJsonHubProtocol.cs index f700261a5e..5caa2c5c0d 100644 --- a/src/SignalR/common/Protocols.NewtonsoftJson/src/Protocol/NewtonsoftJsonHubProtocol.cs +++ b/src/SignalR/common/Protocols.NewtonsoftJson/src/Protocol/NewtonsoftJsonHubProtocol.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Buffers; using System.Collections.Generic; diff --git a/src/SignalR/common/Shared/AsyncEnumerableAdapters.cs b/src/SignalR/common/Shared/AsyncEnumerableAdapters.cs index 5dfbffacd9..8139ca0eeb 100644 --- a/src/SignalR/common/Shared/AsyncEnumerableAdapters.cs +++ b/src/SignalR/common/Shared/AsyncEnumerableAdapters.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/src/SignalR/common/Shared/MemoryBufferWriter.cs b/src/SignalR/common/Shared/MemoryBufferWriter.cs index 1ccb745df4..69b2771209 100644 --- a/src/SignalR/common/Shared/MemoryBufferWriter.cs +++ b/src/SignalR/common/Shared/MemoryBufferWriter.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Buffers; using System.Collections.Generic; diff --git a/src/SignalR/common/Shared/PipeWriterStream.cs b/src/SignalR/common/Shared/PipeWriterStream.cs index 43474433f4..56b2a0f662 100644 --- a/src/SignalR/common/Shared/PipeWriterStream.cs +++ b/src/SignalR/common/Shared/PipeWriterStream.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System.Buffers; using System.Threading; using System.Threading.Tasks; diff --git a/src/SignalR/common/Shared/ReflectionHelper.cs b/src/SignalR/common/Shared/ReflectionHelper.cs index f6d33cac3e..93b613f840 100644 --- a/src/SignalR/common/Shared/ReflectionHelper.cs +++ b/src/SignalR/common/Shared/ReflectionHelper.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/src/SignalR/common/Shared/ReusableUtf8JsonWriter.cs b/src/SignalR/common/Shared/ReusableUtf8JsonWriter.cs index c05c0397e6..ebc038c4ba 100644 --- a/src/SignalR/common/Shared/ReusableUtf8JsonWriter.cs +++ b/src/SignalR/common/Shared/ReusableUtf8JsonWriter.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Buffers; using System.Text.Encodings.Web; diff --git a/src/SignalR/common/Shared/SystemTextJsonExtensions.cs b/src/SignalR/common/Shared/SystemTextJsonExtensions.cs index f17d38a858..a27ce2c270 100644 --- a/src/SignalR/common/Shared/SystemTextJsonExtensions.cs +++ b/src/SignalR/common/Shared/SystemTextJsonExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + using System.IO; using System.Text.Json; @@ -69,7 +71,7 @@ namespace Microsoft.AspNetCore.Internal }; } - public static string ReadAsString(this ref Utf8JsonReader reader, string propertyName) + public static string? ReadAsString(this ref Utf8JsonReader reader, string propertyName) { reader.Read(); diff --git a/src/SignalR/common/Shared/TimerAwaitable.cs b/src/SignalR/common/Shared/TimerAwaitable.cs index c40d55b42d..959e2ef31d 100644 --- a/src/SignalR/common/Shared/TimerAwaitable.cs +++ b/src/SignalR/common/Shared/TimerAwaitable.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + using System; using System.Runtime.CompilerServices; using System.Threading; @@ -10,8 +12,8 @@ namespace Microsoft.AspNetCore.Internal { internal class TimerAwaitable : IDisposable, ICriticalNotifyCompletion { - private Timer _timer; - private Action _callback; + private Timer? _timer; + private Action? _callback; private static readonly Action _callbackCompleted = () => { }; private readonly TimeSpan _period; @@ -55,7 +57,7 @@ namespace Microsoft.AspNetCore.Internal // If TimerAwaitable falls out of scope, the timer should be released. _timer = new Timer(state => { - var weakRef = (WeakReference)state; + var weakRef = (WeakReference)state!; if (weakRef.TryGetTarget(out var thisRef)) { thisRef.Tick(); diff --git a/src/SignalR/common/Shared/Utf8BufferTextReader.cs b/src/SignalR/common/Shared/Utf8BufferTextReader.cs index 0acb774c00..dc0084bfb0 100644 --- a/src/SignalR/common/Shared/Utf8BufferTextReader.cs +++ b/src/SignalR/common/Shared/Utf8BufferTextReader.cs @@ -1,6 +1,8 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Buffers; using System.IO; diff --git a/src/SignalR/common/Shared/Utf8BufferTextWriter.cs b/src/SignalR/common/Shared/Utf8BufferTextWriter.cs index e2db2c7877..b33917d061 100644 --- a/src/SignalR/common/Shared/Utf8BufferTextWriter.cs +++ b/src/SignalR/common/Shared/Utf8BufferTextWriter.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Buffers; using System.Diagnostics; diff --git a/src/SignalR/common/SignalR.Common/src/HubException.cs b/src/SignalR/common/SignalR.Common/src/HubException.cs index 569437573c..dbf19031ac 100644 --- a/src/SignalR/common/SignalR.Common/src/HubException.cs +++ b/src/SignalR/common/SignalR.Common/src/HubException.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.SignalR /// with a specified error message. /// /// The error message that explains the reason for the exception. - public HubException(string message) : base(message) + public HubException(string? message) : base(message) { } @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.SignalR /// /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, or null if no inner exception is specified. - public HubException(string message, Exception innerException) : base(message, innerException) + public HubException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/src/SignalR/common/SignalR.Common/src/Microsoft.AspNetCore.SignalR.Common.csproj b/src/SignalR/common/SignalR.Common/src/Microsoft.AspNetCore.SignalR.Common.csproj index 17252e2b1f..ff1a013cf8 100644 --- a/src/SignalR/common/SignalR.Common/src/Microsoft.AspNetCore.SignalR.Common.csproj +++ b/src/SignalR/common/SignalR.Common/src/Microsoft.AspNetCore.SignalR.Common.csproj @@ -1,4 +1,4 @@ - + Common serialiation primitives for SignalR Clients Servers @@ -7,6 +7,7 @@ true Microsoft.AspNetCore.SignalR true + enable diff --git a/src/SignalR/common/SignalR.Common/src/Protocol/CloseMessage.cs b/src/SignalR/common/SignalR.Common/src/Protocol/CloseMessage.cs index 4dfa28f63d..eceb78ccb4 100644 --- a/src/SignalR/common/SignalR.Common/src/Protocol/CloseMessage.cs +++ b/src/SignalR/common/SignalR.Common/src/Protocol/CloseMessage.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// /// Gets the optional error message. /// - public string Error { get; } + public string? Error { get; } /// /// If , clients with automatic reconnects enabled should not attempt to automatically reconnect after receiving the . @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// Initializes a new instance of the class with an optional error message and set to . /// /// An optional error message. - public CloseMessage(string error) + public CloseMessage(string? error) : this(error, allowReconnect: false) { } @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// , if client with automatic reconnects enabled should attempt to reconnect after receiving the ; /// , if the client should not try to reconnect whether or not automatic reconnects are enabled. /// - public CloseMessage(string error, bool allowReconnect) + public CloseMessage(string? error, bool allowReconnect) { Error = error; AllowReconnect = allowReconnect; diff --git a/src/SignalR/common/SignalR.Common/src/Protocol/CompletionMessage.cs b/src/SignalR/common/SignalR.Common/src/Protocol/CompletionMessage.cs index ec507c4812..797e0f6dfe 100644 --- a/src/SignalR/common/SignalR.Common/src/Protocol/CompletionMessage.cs +++ b/src/SignalR/common/SignalR.Common/src/Protocol/CompletionMessage.cs @@ -2,17 +2,16 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; namespace Microsoft.AspNetCore.SignalR.Protocol { public class CompletionMessage : HubInvocationMessage { - public string Error { get; } - public object Result { get; } + public string? Error { get; } + public object? Result { get; } public bool HasResult { get; } - public CompletionMessage(string invocationId, string error, object result, bool hasResult) + public CompletionMessage(string invocationId, string? error, object? result, bool hasResult) : base(invocationId) { if (error != null && result != null) diff --git a/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeProtocol.cs b/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeProtocol.cs index db83cd073a..6a303a445b 100644 --- a/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeProtocol.cs +++ b/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeProtocol.cs @@ -5,6 +5,7 @@ using System; using System.Buffers; using System.Collections.Concurrent; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Text; using System.Text.Json; @@ -109,7 +110,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// The serialized representation of the message. /// When this method returns, contains the parsed message. /// A value that is true if the was successfully parsed; otherwise, false. - public static bool TryParseResponseMessage(ref ReadOnlySequence buffer, out HandshakeResponseMessage responseMessage) + public static bool TryParseResponseMessage(ref ReadOnlySequence buffer, [NotNullWhen(true)] out HandshakeResponseMessage? responseMessage) { if (!TextMessageParser.TryParseMessage(ref buffer, out var payload)) { @@ -122,7 +123,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol reader.CheckRead(); reader.EnsureObjectStart(); - string error = null; + string? error = null; while (reader.CheckRead()) { @@ -163,7 +164,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// The serialized representation of the message. /// When this method returns, contains the parsed message. /// A value that is true if the was successfully parsed; otherwise, false. - public static bool TryParseRequestMessage(ref ReadOnlySequence buffer, out HandshakeRequestMessage requestMessage) + public static bool TryParseRequestMessage(ref ReadOnlySequence buffer, [NotNullWhen(true)] out HandshakeRequestMessage? requestMessage) { if (!TextMessageParser.TryParseMessage(ref buffer, out var payload)) { @@ -176,7 +177,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol reader.CheckRead(); reader.EnsureObjectStart(); - string protocol = null; + string? protocol = null; int? protocolVersion = null; while (reader.CheckRead()) diff --git a/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeRequestMessage.cs b/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeRequestMessage.cs index 41c82b08fe..76bf977650 100644 --- a/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeRequestMessage.cs +++ b/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeRequestMessage.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.AspNetCore.SignalR.Protocol diff --git a/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeResponseMessage.cs b/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeResponseMessage.cs index 836da79bb4..bcd8ccc9fa 100644 --- a/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeResponseMessage.cs +++ b/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeResponseMessage.cs @@ -16,14 +16,14 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// /// Gets the optional error message. /// - public string Error { get; } + public string? Error { get; } /// /// Initializes a new instance of the class. /// An error response does need a minor version. Since the handshake has failed, any extra data will be ignored. /// /// Error encountered by the server, indicating why the handshake has failed. - public HandshakeResponseMessage(string error) + public HandshakeResponseMessage(string? error) { Error = error; } diff --git a/src/SignalR/common/SignalR.Common/src/Protocol/HubInvocationMessage.cs b/src/SignalR/common/SignalR.Common/src/Protocol/HubInvocationMessage.cs index 32e9f25d03..ef411137c0 100644 --- a/src/SignalR/common/SignalR.Common/src/Protocol/HubInvocationMessage.cs +++ b/src/SignalR/common/SignalR.Common/src/Protocol/HubInvocationMessage.cs @@ -13,18 +13,18 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// /// Gets or sets a name/value collection of headers. /// - public IDictionary Headers { get; set; } + public IDictionary? Headers { get; set; } /// /// Gets the invocation ID. /// - public string InvocationId { get; } + public string? InvocationId { get; } /// /// Initializes a new instance of the class. /// /// The invocation ID. - protected HubInvocationMessage(string invocationId) + protected HubInvocationMessage(string? invocationId) { InvocationId = invocationId; } diff --git a/src/SignalR/common/SignalR.Common/src/Protocol/HubMethodInvocationMessage.cs b/src/SignalR/common/SignalR.Common/src/Protocol/HubMethodInvocationMessage.cs index a2cb0c58de..cbe3f23ce3 100644 --- a/src/SignalR/common/SignalR.Common/src/Protocol/HubMethodInvocationMessage.cs +++ b/src/SignalR/common/SignalR.Common/src/Protocol/HubMethodInvocationMessage.cs @@ -19,12 +19,12 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// /// Gets the target method arguments. /// - public object[] Arguments { get; } + public object?[]? Arguments { get; } /// /// The target methods stream IDs. /// - public string[] StreamIds { get; } + public string[]? StreamIds { get; } /// /// Initializes a new instance of the class. @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// The target method name. /// The target method arguments. /// The target methods stream IDs. - protected HubMethodInvocationMessage(string invocationId, string target, object[] arguments, string[] streamIds) + protected HubMethodInvocationMessage(string? invocationId, string target, object?[]? arguments, string[]? streamIds) : this(invocationId, target, arguments) { StreamIds = streamIds; @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// The invocation ID. /// The target method name. /// The target method arguments. - protected HubMethodInvocationMessage(string invocationId, string target, object[] arguments) + protected HubMethodInvocationMessage(string? invocationId, string target, object?[]? arguments) : base(invocationId) { if (string.IsNullOrEmpty(target)) @@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// /// The target method name. /// The target method arguments. - public InvocationMessage(string target, object[] arguments) + public InvocationMessage(string target, object?[]? arguments) : this(null, target, arguments) { } @@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// The invocation ID. /// The target method name. /// The target method arguments. - public InvocationMessage(string invocationId, string target, object[] arguments) + public InvocationMessage(string? invocationId, string target, object?[]? arguments) : base(invocationId, target, arguments) { } @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// The target method name. /// The target method arguments. /// The target methods stream IDs. - public InvocationMessage(string invocationId, string target, object[] arguments, string[] streamIds) + public InvocationMessage(string? invocationId, string target, object?[]? arguments, string[]? streamIds) : base(invocationId, target, arguments, streamIds) { } @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol string streamIds; try { - args = string.Join(", ", Arguments?.Select(a => a?.ToString())); + args = Arguments == null ? string.Empty : string.Join(", ", Arguments.Select(a => a?.ToString())); } catch (Exception ex) { @@ -158,7 +158,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol string streamIds; try { - args = string.Join(", ", Arguments?.Select(a => a?.ToString())); + args = Arguments == null ? string.Empty : string.Join(", ", Arguments.Select(a => a?.ToString())); } catch (Exception ex) { diff --git a/src/SignalR/common/SignalR.Common/src/Protocol/IHubProtocol.cs b/src/SignalR/common/SignalR.Common/src/Protocol/IHubProtocol.cs index b235e14e54..d81af13339 100644 --- a/src/SignalR/common/SignalR.Common/src/Protocol/IHubProtocol.cs +++ b/src/SignalR/common/SignalR.Common/src/Protocol/IHubProtocol.cs @@ -3,6 +3,7 @@ using System; using System.Buffers; +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Connections; namespace Microsoft.AspNetCore.SignalR.Protocol @@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.SignalR.Protocol /// The binder used to parse the message. /// When this method returns true, contains the parsed message. /// A value that is true if the was successfully parsed; otherwise, false. - bool TryParseMessage(ref ReadOnlySequence input, IInvocationBinder binder, out HubMessage message); + bool TryParseMessage(ref ReadOnlySequence input, IInvocationBinder binder, [NotNullWhen(true)] out HubMessage message); /// /// Writes the specified to a writer. diff --git a/src/SignalR/common/SignalR.Common/src/Protocol/StreamItemMessage.cs b/src/SignalR/common/SignalR.Common/src/Protocol/StreamItemMessage.cs index cf885e837f..c518622b0a 100644 --- a/src/SignalR/common/SignalR.Common/src/Protocol/StreamItemMessage.cs +++ b/src/SignalR/common/SignalR.Common/src/Protocol/StreamItemMessage.cs @@ -5,9 +5,9 @@ namespace Microsoft.AspNetCore.SignalR.Protocol { public class StreamItemMessage : HubInvocationMessage { - public object Item { get; } + public object? Item { get; } - public StreamItemMessage(string invocationId, object item) : base(invocationId) + public StreamItemMessage(string invocationId, object? item) : base(invocationId) { Item = item; } diff --git a/src/SignalR/server/Core/src/ClientProxyExtensions.cs b/src/SignalR/server/Core/src/ClientProxyExtensions.cs index 2e21956e91..2226006a0b 100644 --- a/src/SignalR/server/Core/src/ClientProxyExtensions.cs +++ b/src/SignalR/server/Core/src/ClientProxyExtensions.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.SignalR /// The first argument. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, CancellationToken cancellationToken = default) + public static Task SendAsync(this IClientProxy clientProxy, string method, object? arg1, CancellationToken cancellationToken = default) { return clientProxy.SendCoreAsync(method, new[] { arg1 }, cancellationToken); } @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.SignalR /// The second argument. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, CancellationToken cancellationToken = default) + public static Task SendAsync(this IClientProxy clientProxy, string method, object? arg1, object? arg2, CancellationToken cancellationToken = default) { return clientProxy.SendCoreAsync(method, new[] { arg1, arg2 }, cancellationToken); } @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.SignalR /// The third argument. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default) + public static Task SendAsync(this IClientProxy clientProxy, string method, object? arg1, object? arg2, object? arg3, CancellationToken cancellationToken = default) { return clientProxy.SendCoreAsync(method, new[] { arg1, arg2, arg3 }, cancellationToken); } @@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.SignalR /// The fourth argument. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default) + public static Task SendAsync(this IClientProxy clientProxy, string method, object? arg1, object? arg2, object? arg3, object? arg4, CancellationToken cancellationToken = default) { return clientProxy.SendCoreAsync(method, new[] { arg1, arg2, arg3, arg4 }, cancellationToken); } @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.SignalR /// The fifth argument. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default) + public static Task SendAsync(this IClientProxy clientProxy, string method, object? arg1, object? arg2, object? arg3, object? arg4, object? arg5, CancellationToken cancellationToken = default) { return clientProxy.SendCoreAsync(method, new[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken); } @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.SignalR /// The sixth argument. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default) + public static Task SendAsync(this IClientProxy clientProxy, string method, object? arg1, object? arg2, object? arg3, object? arg4, object? arg5, object? arg6, CancellationToken cancellationToken = default) { return clientProxy.SendCoreAsync(method, new[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken); } @@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.SignalR /// The seventh argument. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default) + public static Task SendAsync(this IClientProxy clientProxy, string method, object? arg1, object? arg2, object? arg3, object? arg4, object? arg5, object? arg6, object? arg7, CancellationToken cancellationToken = default) { return clientProxy.SendCoreAsync(method, new[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken); } @@ -160,7 +160,7 @@ namespace Microsoft.AspNetCore.SignalR /// The eigth argument. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default) + public static Task SendAsync(this IClientProxy clientProxy, string method, object? arg1, object? arg2, object? arg3, object? arg4, object? arg5, object? arg6, object? arg7, object? arg8, CancellationToken cancellationToken = default) { return clientProxy.SendCoreAsync(method, new[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken); } @@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.SignalR /// The ninth argument. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default) + public static Task SendAsync(this IClientProxy clientProxy, string method, object? arg1, object? arg2, object? arg3, object? arg4, object? arg5, object? arg6, object? arg7, object? arg8, object? arg9, CancellationToken cancellationToken = default) { return clientProxy.SendCoreAsync(method, new[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken); } @@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.SignalR /// The tenth argument. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default) + public static Task SendAsync(this IClientProxy clientProxy, string method, object? arg1, object? arg2, object? arg3, object? arg4, object? arg5, object? arg6, object? arg7, object? arg8, object? arg9, object? arg10, CancellationToken cancellationToken = default) { return clientProxy.SendCoreAsync(method, new[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken); } diff --git a/src/SignalR/server/Core/src/DefaultHubLifetimeManager.cs b/src/SignalR/server/Core/src/DefaultHubLifetimeManager.cs index c00264ea2b..55031a6673 100644 --- a/src/SignalR/server/Core/src/DefaultHubLifetimeManager.cs +++ b/src/SignalR/server/Core/src/DefaultHubLifetimeManager.cs @@ -80,15 +80,15 @@ namespace Microsoft.AspNetCore.SignalR } /// - public override Task SendAllAsync(string methodName, object[] args, CancellationToken cancellationToken = default) + public override Task SendAllAsync(string methodName, object?[]? args, CancellationToken cancellationToken = default) { return SendToAllConnections(methodName, args, include: null, state: null, cancellationToken); } - private Task SendToAllConnections(string methodName, object[] args, Func include, object state = null, CancellationToken cancellationToken = default) + private Task SendToAllConnections(string methodName, object?[]? args, Func? include, object? state = null, CancellationToken cancellationToken = default) { - List tasks = null; - SerializedHubMessage message = null; + List? tasks = null; + SerializedHubMessage? message = null; // foreach over HubConnectionStore avoids allocating an enumerator foreach (var connection in _connections) @@ -127,7 +127,7 @@ namespace Microsoft.AspNetCore.SignalR // Tasks and message are passed by ref so they can be lazily created inside the method post-filtering, // while still being re-usable when sending to multiple groups - private void SendToGroupConnections(string methodName, object[] args, ConcurrentDictionary connections, Func include, object state, ref List tasks, ref SerializedHubMessage message, CancellationToken cancellationToken) + private void SendToGroupConnections(string methodName, object?[]? args, ConcurrentDictionary connections, Func? include, object? state, ref List? tasks, ref SerializedHubMessage? message, CancellationToken cancellationToken) { // foreach over ConcurrentDictionary avoids allocating an enumerator foreach (var connection in connections) @@ -157,7 +157,7 @@ namespace Microsoft.AspNetCore.SignalR } /// - public override Task SendConnectionAsync(string connectionId, string methodName, object[] args, CancellationToken cancellationToken = default) + public override Task SendConnectionAsync(string connectionId, string methodName, object?[]? args, CancellationToken cancellationToken = default) { if (connectionId == null) { @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.SignalR } /// - public override Task SendGroupAsync(string groupName, string methodName, object[] args, CancellationToken cancellationToken = default) + public override Task SendGroupAsync(string groupName, string methodName, object?[]? args, CancellationToken cancellationToken = default) { if (groupName == null) { @@ -191,8 +191,8 @@ namespace Microsoft.AspNetCore.SignalR { // Can't optimize for sending to a single connection in a group because // group might be modified inbetween checking and sending - List tasks = null; - SerializedHubMessage message = null; + List? tasks = null; + SerializedHubMessage? message = null; SendToGroupConnections(methodName, args, group, null, null, ref tasks, ref message, cancellationToken); if (tasks != null) @@ -205,11 +205,11 @@ namespace Microsoft.AspNetCore.SignalR } /// - public override Task SendGroupsAsync(IReadOnlyList groupNames, string methodName, object[] args, CancellationToken cancellationToken = default) + public override Task SendGroupsAsync(IReadOnlyList groupNames, string methodName, object?[]? args, CancellationToken cancellationToken = default) { // Each task represents the list of tasks for each of the writes within a group - List tasks = null; - SerializedHubMessage message = null; + List? tasks = null; + SerializedHubMessage? message = null; foreach (var groupName in groupNames) { @@ -234,7 +234,7 @@ namespace Microsoft.AspNetCore.SignalR } /// - public override Task SendGroupExceptAsync(string groupName, string methodName, object[] args, IReadOnlyList excludedConnectionIds, CancellationToken cancellationToken = default) + public override Task SendGroupExceptAsync(string groupName, string methodName, object?[]? args, IReadOnlyList excludedConnectionIds, CancellationToken cancellationToken = default) { if (groupName == null) { @@ -244,10 +244,10 @@ namespace Microsoft.AspNetCore.SignalR var group = _groups[groupName]; if (group != null) { - List tasks = null; - SerializedHubMessage message = null; + List? tasks = null; + SerializedHubMessage? message = null; - SendToGroupConnections(methodName, args, group, (connection, state) => !((IReadOnlyList)state).Contains(connection.ConnectionId), excludedConnectionIds, ref tasks, ref message, cancellationToken); + SendToGroupConnections(methodName, args, group, (connection, state) => !((IReadOnlyList)state!).Contains(connection.ConnectionId), excludedConnectionIds, ref tasks, ref message, cancellationToken); if (tasks != null) { @@ -258,20 +258,20 @@ namespace Microsoft.AspNetCore.SignalR return Task.CompletedTask; } - private SerializedHubMessage CreateSerializedInvocationMessage(string methodName, object[] args) + private SerializedHubMessage CreateSerializedInvocationMessage(string methodName, object?[]? args) { return new SerializedHubMessage(CreateInvocationMessage(methodName, args)); } - private HubMessage CreateInvocationMessage(string methodName, object[] args) + private HubMessage CreateInvocationMessage(string methodName, object?[]? args) { return new InvocationMessage(methodName, args); } /// - public override Task SendUserAsync(string userId, string methodName, object[] args, CancellationToken cancellationToken = default) + public override Task SendUserAsync(string userId, string methodName, object?[]? args, CancellationToken cancellationToken = default) { - return SendToAllConnections(methodName, args, (connection, state) => string.Equals(connection.UserIdentifier, (string)state, StringComparison.Ordinal), userId, cancellationToken); + return SendToAllConnections(methodName, args, (connection, state) => string.Equals(connection.UserIdentifier, (string)state!, StringComparison.Ordinal), userId, cancellationToken); } /// @@ -290,21 +290,21 @@ namespace Microsoft.AspNetCore.SignalR } /// - public override Task SendAllExceptAsync(string methodName, object[] args, IReadOnlyList excludedConnectionIds, CancellationToken cancellationToken = default) + public override Task SendAllExceptAsync(string methodName, object?[]? args, IReadOnlyList excludedConnectionIds, CancellationToken cancellationToken = default) { - return SendToAllConnections(methodName, args, (connection, state) => !((IReadOnlyList)state).Contains(connection.ConnectionId), excludedConnectionIds, cancellationToken); + return SendToAllConnections(methodName, args, (connection, state) => !((IReadOnlyList)state!).Contains(connection.ConnectionId), excludedConnectionIds, cancellationToken); } /// - public override Task SendConnectionsAsync(IReadOnlyList connectionIds, string methodName, object[] args, CancellationToken cancellationToken = default) + public override Task SendConnectionsAsync(IReadOnlyList connectionIds, string methodName, object?[]? args, CancellationToken cancellationToken = default) { - return SendToAllConnections(methodName, args, (connection, state) => ((IReadOnlyList)state).Contains(connection.ConnectionId), connectionIds, cancellationToken); + return SendToAllConnections(methodName, args, (connection, state) => ((IReadOnlyList)state!).Contains(connection.ConnectionId), connectionIds, cancellationToken); } /// - public override Task SendUsersAsync(IReadOnlyList userIds, string methodName, object[] args, CancellationToken cancellationToken = default) + public override Task SendUsersAsync(IReadOnlyList userIds, string methodName, object?[]? args, CancellationToken cancellationToken = default) { - return SendToAllConnections(methodName, args, (connection, state) => ((IReadOnlyList)state).Contains(connection.UserIdentifier), userIds, cancellationToken); + return SendToAllConnections(methodName, args, (connection, state) => ((IReadOnlyList)state!).Contains(connection.UserIdentifier), userIds, cancellationToken); } } } diff --git a/src/SignalR/server/Core/src/DefaultUserIdProvider.cs b/src/SignalR/server/Core/src/DefaultUserIdProvider.cs index 809114eb68..b3c42f6b3a 100644 --- a/src/SignalR/server/Core/src/DefaultUserIdProvider.cs +++ b/src/SignalR/server/Core/src/DefaultUserIdProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Security.Claims; @@ -12,9 +12,9 @@ namespace Microsoft.AspNetCore.SignalR public class DefaultUserIdProvider : IUserIdProvider { /// - public virtual string GetUserId(HubConnectionContext connection) + public virtual string? GetUserId(HubConnectionContext connection) { return connection.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; } } -} \ No newline at end of file +} diff --git a/src/SignalR/server/Core/src/DynamicHub.cs b/src/SignalR/server/Core/src/DynamicHub.cs index 2941b32ee5..bb89998cd6 100644 --- a/src/SignalR/server/Core/src/DynamicHub.cs +++ b/src/SignalR/server/Core/src/DynamicHub.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.AspNetCore.SignalR @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.SignalR /// public abstract class DynamicHub : Hub { - private DynamicHubClients _clients; + private DynamicHubClients? _clients; /// /// Gets or sets an object that can be used to invoke methods on the clients connected to this hub. diff --git a/src/SignalR/server/Core/src/Hub.cs b/src/SignalR/server/Core/src/Hub.cs index 544c6bcee1..2b28e808f6 100644 --- a/src/SignalR/server/Core/src/Hub.cs +++ b/src/SignalR/server/Core/src/Hub.cs @@ -12,9 +12,9 @@ namespace Microsoft.AspNetCore.SignalR public abstract class Hub : IDisposable { private bool _disposed; - private IHubCallerClients _clients; - private HubCallerContext _context; - private IGroupManager _groups; + private IHubCallerClients _clients = default!; + private HubCallerContext _context = default!; + private IGroupManager _groups = default!; /// /// Gets or sets an object that can be used to invoke methods on the clients connected to this hub. @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.SignalR /// Called when a connection with the hub is terminated. /// /// A that represents the asynchronous disconnect. - public virtual Task OnDisconnectedAsync(Exception exception) + public virtual Task OnDisconnectedAsync(Exception? exception) { return Task.CompletedTask; } diff --git a/src/SignalR/server/Core/src/HubCallerContext.cs b/src/SignalR/server/Core/src/HubCallerContext.cs index b0a30b3820..7d361e996e 100644 --- a/src/SignalR/server/Core/src/HubCallerContext.cs +++ b/src/SignalR/server/Core/src/HubCallerContext.cs @@ -21,17 +21,17 @@ namespace Microsoft.AspNetCore.SignalR /// /// Gets the user identifier. /// - public abstract string UserIdentifier { get; } + public abstract string? UserIdentifier { get; } /// /// Gets the user. /// - public abstract ClaimsPrincipal User { get; } + public abstract ClaimsPrincipal? User { get; } /// /// Gets a key/value collection that can be used to share data within the scope of this connection. /// - public abstract IDictionary Items { get; } + public abstract IDictionary Items { get; } /// /// Gets the collection of HTTP features available on the connection. diff --git a/src/SignalR/server/Core/src/HubConnectionContext.Log.cs b/src/SignalR/server/Core/src/HubConnectionContext.Log.cs new file mode 100644 index 0000000000..870d4a6245 --- /dev/null +++ b/src/SignalR/server/Core/src/HubConnectionContext.Log.cs @@ -0,0 +1,97 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +#nullable disable + +using System; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.SignalR +{ + public partial class HubConnectionContext + { + private static class Log + { + // Category: HubConnectionContext + private static readonly Action _handshakeComplete = + LoggerMessage.Define(LogLevel.Debug, new EventId(1, "HandshakeComplete"), "Completed connection handshake. Using HubProtocol '{Protocol}'."); + + private static readonly Action _handshakeCanceled = + LoggerMessage.Define(LogLevel.Debug, new EventId(2, "HandshakeCanceled"), "Handshake was canceled."); + + private static readonly Action _sentPing = + LoggerMessage.Define(LogLevel.Trace, new EventId(3, "SentPing"), "Sent a ping message to the client."); + + private static readonly Action _transportBufferFull = + LoggerMessage.Define(LogLevel.Debug, new EventId(4, "TransportBufferFull"), "Unable to send Ping message to client, the transport buffer is full."); + + private static readonly Action _handshakeFailed = + LoggerMessage.Define(LogLevel.Debug, new EventId(5, "HandshakeFailed"), "Failed connection handshake."); + + private static readonly Action _failedWritingMessage = + LoggerMessage.Define(LogLevel.Error, new EventId(6, "FailedWritingMessage"), "Failed writing message. Aborting connection."); + + private static readonly Action _protocolVersionFailed = + LoggerMessage.Define(LogLevel.Debug, new EventId(7, "ProtocolVersionFailed"), "Server does not support version {Version} of the {Protocol} protocol."); + + private static readonly Action _abortFailed = + LoggerMessage.Define(LogLevel.Trace, new EventId(8, "AbortFailed"), "Abort callback failed."); + + private static readonly Action _clientTimeout = + LoggerMessage.Define(LogLevel.Debug, new EventId(9, "ClientTimeout"), "Client timeout ({ClientTimeout}ms) elapsed without receiving a message from the client. Closing connection."); + + private static readonly Action _handshakeSizeLimitExceeded = + LoggerMessage.Define(LogLevel.Debug, new EventId(10, "HandshakeSizeLimitExceeded"), "The maximum message size of {MaxMessageSize}B was exceeded while parsing the Handshake. The message size can be configured in AddHubOptions."); + + public static void HandshakeComplete(ILogger logger, string hubProtocol) + { + _handshakeComplete(logger, hubProtocol, null); + } + + public static void HandshakeCanceled(ILogger logger) + { + _handshakeCanceled(logger, null); + } + + public static void SentPing(ILogger logger) + { + _sentPing(logger, null); + } + + public static void TransportBufferFull(ILogger logger) + { + _transportBufferFull(logger, null); + } + + public static void HandshakeFailed(ILogger logger, Exception exception) + { + _handshakeFailed(logger, exception); + } + + public static void FailedWritingMessage(ILogger logger, Exception exception) + { + _failedWritingMessage(logger, exception); + } + + public static void ProtocolVersionFailed(ILogger logger, string protocolName, int version) + { + _protocolVersionFailed(logger, protocolName, version, null); + } + + public static void AbortFailed(ILogger logger, Exception exception) + { + _abortFailed(logger, exception); + } + + public static void ClientTimeout(ILogger logger, TimeSpan timeout) + { + _clientTimeout(logger, (int)timeout.TotalMilliseconds, null); + } + + public static void HandshakeSizeLimitExceeded(ILogger logger, long maxMessageSize) + { + _handshakeSizeLimitExceeded(logger, maxMessageSize, null); + } + } + } +} diff --git a/src/SignalR/server/Core/src/HubConnectionContext.cs b/src/SignalR/server/Core/src/HubConnectionContext.cs index e0a6d758f6..0e98a6ee08 100644 --- a/src/SignalR/server/Core/src/HubConnectionContext.cs +++ b/src/SignalR/server/Core/src/HubConnectionContext.cs @@ -23,9 +23,9 @@ namespace Microsoft.AspNetCore.SignalR /// /// Encapsulates all information about an individual connection to a SignalR Hub. /// - public class HubConnectionContext + public partial class HubConnectionContext { - private static readonly Action _cancelReader = state => ((PipeReader)state).CancelPendingRead(); + private static readonly Action _cancelReader = state => ((PipeReader)state!).CancelPendingRead(); private static readonly WaitCallback _abortedCallback = AbortConnection; private readonly ConnectionContext _connectionContext; @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.SignalR private readonly ISystemClock _systemClock; private readonly CancellationTokenRegistration _closedRegistration; - private StreamTracker _streamTracker; + private StreamTracker? _streamTracker; private long _lastSendTimeStamp; private ReadOnlyMemory _cachedPingMessage; private bool _clientTimeoutActive; @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.SignalR _connectionContext = connectionContext; _logger = loggerFactory.CreateLogger(); ConnectionAborted = _connectionAbortedTokenSource.Token; - _closedRegistration = connectionContext.ConnectionClosed.Register((state) => ((HubConnectionContext)state).Abort(), this); + _closedRegistration = connectionContext.ConnectionClosed.Register((state) => ((HubConnectionContext)state!).Abort(), this); HubCallerContext = new DefaultHubCallerContext(this); @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.SignalR internal HubCallerContext HubCallerContext { get; } - internal Exception CloseException { get; private set; } + internal Exception? CloseException { get; private set; } /// /// Gets a that notifies when the connection is aborted. @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.SignalR /// /// Gets the user for this connection. /// - public virtual ClaimsPrincipal User => Features.Get()?.User; + public virtual ClaimsPrincipal? User => Features.Get()?.User; /// /// Gets the collection of features available on this connection. @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.SignalR /// /// Gets a key/value collection that can be used to share data within the scope of this connection. /// - public virtual IDictionary Items => _connectionContext.Items; + public virtual IDictionary Items => _connectionContext.Items; // Used by HubConnectionHandler to determine whether to set CloseMessage.AllowReconnect. internal bool AllowReconnect => _allowReconnect; @@ -127,12 +127,12 @@ namespace Microsoft.AspNetCore.SignalR /// /// Gets or sets the user identifier for this connection. /// - public string UserIdentifier { get; set; } + public string? UserIdentifier { get; set; } /// /// Gets the protocol used by this connection. /// - public virtual IHubProtocol Protocol { get; set; } + public virtual IHubProtocol Protocol { get; set; } = default!; // Currently used only for streaming methods internal ConcurrentDictionary ActiveRequestCancellationSources { get; } = new ConcurrentDictionary(StringComparer.Ordinal); @@ -405,7 +405,7 @@ namespace Microsoft.AspNetCore.SignalR ThreadPool.QueueUserWorkItem(_abortedCallback, this); } - internal async Task HandshakeAsync(TimeSpan timeout, IReadOnlyList supportedProtocols, IHubProtocolResolver protocolResolver, + internal async Task HandshakeAsync(TimeSpan timeout, IReadOnlyList? supportedProtocols, IHubProtocolResolver protocolResolver, IUserIdProvider userIdProvider, bool enableDetailedErrors) { try @@ -455,7 +455,7 @@ namespace Microsoft.AspNetCore.SignalR consumed = segment.Start; examined = consumed; - Protocol = protocolResolver.GetProtocol(handshakeRequestMessage.Protocol, supportedProtocols); + Protocol = protocolResolver.GetProtocol(handshakeRequestMessage.Protocol, supportedProtocols)!; if (Protocol == null) { Log.HandshakeFailed(_logger, null); @@ -506,7 +506,7 @@ namespace Microsoft.AspNetCore.SignalR } else if (overLength) { - Log.HandshakeSizeLimitExceeded(_logger, _maxMessageSize.Value); + Log.HandshakeSizeLimitExceeded(_logger, _maxMessageSize!.Value); await WriteHandshakeResponseAsync(new HandshakeResponseMessage("Handshake was canceled.")); return false; } @@ -619,9 +619,9 @@ namespace Microsoft.AspNetCore.SignalR } } - private static void AbortConnection(object state) + private static void AbortConnection(object? state) { - var connection = (HubConnectionContext)state; + var connection = (HubConnectionContext)state!; try { @@ -684,89 +684,5 @@ namespace Microsoft.AspNetCore.SignalR _streamTracker.CompleteAll(new OperationCanceledException("The underlying connection was closed.")); } } - - private static class Log - { - // Category: HubConnectionContext - private static readonly Action _handshakeComplete = - LoggerMessage.Define(LogLevel.Debug, new EventId(1, "HandshakeComplete"), "Completed connection handshake. Using HubProtocol '{Protocol}'."); - - private static readonly Action _handshakeCanceled = - LoggerMessage.Define(LogLevel.Debug, new EventId(2, "HandshakeCanceled"), "Handshake was canceled."); - - private static readonly Action _sentPing = - LoggerMessage.Define(LogLevel.Trace, new EventId(3, "SentPing"), "Sent a ping message to the client."); - - private static readonly Action _transportBufferFull = - LoggerMessage.Define(LogLevel.Debug, new EventId(4, "TransportBufferFull"), "Unable to send Ping message to client, the transport buffer is full."); - - private static readonly Action _handshakeFailed = - LoggerMessage.Define(LogLevel.Debug, new EventId(5, "HandshakeFailed"), "Failed connection handshake."); - - private static readonly Action _failedWritingMessage = - LoggerMessage.Define(LogLevel.Error, new EventId(6, "FailedWritingMessage"), "Failed writing message. Aborting connection."); - - private static readonly Action _protocolVersionFailed = - LoggerMessage.Define(LogLevel.Debug, new EventId(7, "ProtocolVersionFailed"), "Server does not support version {Version} of the {Protocol} protocol."); - - private static readonly Action _abortFailed = - LoggerMessage.Define(LogLevel.Trace, new EventId(8, "AbortFailed"), "Abort callback failed."); - - private static readonly Action _clientTimeout = - LoggerMessage.Define(LogLevel.Debug, new EventId(9, "ClientTimeout"), "Client timeout ({ClientTimeout}ms) elapsed without receiving a message from the client. Closing connection."); - - private static readonly Action _handshakeSizeLimitExceeded = - LoggerMessage.Define(LogLevel.Debug, new EventId(10, "HandshakeSizeLimitExceeded"), "The maximum message size of {MaxMessageSize}B was exceeded while parsing the Handshake. The message size can be configured in AddHubOptions."); - - public static void HandshakeComplete(ILogger logger, string hubProtocol) - { - _handshakeComplete(logger, hubProtocol, null); - } - - public static void HandshakeCanceled(ILogger logger) - { - _handshakeCanceled(logger, null); - } - - public static void SentPing(ILogger logger) - { - _sentPing(logger, null); - } - - public static void TransportBufferFull(ILogger logger) - { - _transportBufferFull(logger, null); - } - - public static void HandshakeFailed(ILogger logger, Exception exception) - { - _handshakeFailed(logger, exception); - } - - public static void FailedWritingMessage(ILogger logger, Exception exception) - { - _failedWritingMessage(logger, exception); - } - - public static void ProtocolVersionFailed(ILogger logger, string protocolName, int version) - { - _protocolVersionFailed(logger, protocolName, version, null); - } - - public static void AbortFailed(ILogger logger, Exception exception) - { - _abortFailed(logger, exception); - } - - public static void ClientTimeout(ILogger logger, TimeSpan timeout) - { - _clientTimeout(logger, (int)timeout.TotalMilliseconds, null); - } - - public static void HandshakeSizeLimitExceeded(ILogger logger, long maxMessageSize) - { - _handshakeSizeLimitExceeded(logger, maxMessageSize, null); - } - } } } diff --git a/src/SignalR/server/Core/src/HubConnectionContextOptions.cs b/src/SignalR/server/Core/src/HubConnectionContextOptions.cs index fc1d34383e..4626d195cc 100644 --- a/src/SignalR/server/Core/src/HubConnectionContextOptions.cs +++ b/src/SignalR/server/Core/src/HubConnectionContextOptions.cs @@ -31,6 +31,6 @@ namespace Microsoft.AspNetCore.SignalR /// public long? MaximumReceiveMessageSize { get; set; } - internal ISystemClock SystemClock { get; set; } + internal ISystemClock SystemClock { get; set; } = default!; } } diff --git a/src/SignalR/server/Core/src/HubConnectionHandler.cs b/src/SignalR/server/Core/src/HubConnectionHandler.cs index 6ef96034ad..c5970a96a6 100644 --- a/src/SignalR/server/Core/src/HubConnectionHandler.cs +++ b/src/SignalR/server/Core/src/HubConnectionHandler.cs @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.SignalR _enableDetailedErrors = false; - List hubFilters = null; + List? hubFilters = null; if (_hubOptions.UserHasSetValues) { _maximumMessageSize = _hubOptions.MaximumReceiveMessageSize; @@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.SignalR await HubOnDisconnectedAsync(connection, connection.CloseException); } - private async Task HubOnDisconnectedAsync(HubConnectionContext connection, Exception exception) + private async Task HubOnDisconnectedAsync(HubConnectionContext connection, Exception? exception) { // send close message before aborting the connection await SendCloseAsync(connection, exception, connection.AllowReconnect); @@ -207,7 +207,7 @@ namespace Microsoft.AspNetCore.SignalR } } - private async Task SendCloseAsync(HubConnectionContext connection, Exception exception, bool allowReconnect) + private async Task SendCloseAsync(HubConnectionContext connection, Exception? exception, bool allowReconnect) { var closeMessage = CloseMessage.Empty; @@ -335,22 +335,22 @@ namespace Microsoft.AspNetCore.SignalR private static class Log { - private static readonly Action _errorDispatchingHubEvent = + private static readonly Action _errorDispatchingHubEvent = LoggerMessage.Define(LogLevel.Error, new EventId(1, "ErrorDispatchingHubEvent"), "Error when dispatching '{HubMethod}' on hub."); - private static readonly Action _errorProcessingRequest = + private static readonly Action _errorProcessingRequest = LoggerMessage.Define(LogLevel.Debug, new EventId(2, "ErrorProcessingRequest"), "Error when processing requests."); - private static readonly Action _abortFailed = + private static readonly Action _abortFailed = LoggerMessage.Define(LogLevel.Trace, new EventId(3, "AbortFailed"), "Abort callback failed."); - private static readonly Action _errorSendingClose = + private static readonly Action _errorSendingClose = LoggerMessage.Define(LogLevel.Debug, new EventId(4, "ErrorSendingClose"), "Error when sending Close message."); - private static readonly Action _connectedStarting = + private static readonly Action _connectedStarting = LoggerMessage.Define(LogLevel.Debug, new EventId(5, "ConnectedStarting"), "OnConnectedAsync started."); - private static readonly Action _connectedEnding = + private static readonly Action _connectedEnding = LoggerMessage.Define(LogLevel.Debug, new EventId(6, "ConnectedEnding"), "OnConnectedAsync ending."); public static void ErrorDispatchingHubEvent(ILogger logger, string hubMethod, Exception exception) diff --git a/src/SignalR/server/Core/src/HubConnectionStore.cs b/src/SignalR/server/Core/src/HubConnectionStore.cs index a94ccda601..9457d0e361 100644 --- a/src/SignalR/server/Core/src/HubConnectionStore.cs +++ b/src/SignalR/server/Core/src/HubConnectionStore.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.SignalR private readonly ConcurrentDictionary _connections = new ConcurrentDictionary(StringComparer.Ordinal); - public HubConnectionContext this[string connectionId] + public HubConnectionContext? this[string connectionId] { get { diff --git a/src/SignalR/server/Core/src/HubInvocationContext.cs b/src/SignalR/server/Core/src/HubInvocationContext.cs index 294e80a6a7..bd08ded072 100644 --- a/src/SignalR/server/Core/src/HubInvocationContext.cs +++ b/src/SignalR/server/Core/src/HubInvocationContext.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.SignalR /// public class HubInvocationContext { - internal ObjectMethodExecutor ObjectMethodExecutor { get; } + internal ObjectMethodExecutor ObjectMethodExecutor { get; } = default!; /// /// Instantiates a new instance of the class. @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.SignalR /// The instance of the Hub. /// The for the Hub method being invoked. /// The arguments provided by the client. - public HubInvocationContext(HubCallerContext context, IServiceProvider serviceProvider, Hub hub, MethodInfo hubMethod, IReadOnlyList hubMethodArguments) + public HubInvocationContext(HubCallerContext context, IServiceProvider serviceProvider, Hub hub, MethodInfo hubMethod, IReadOnlyList hubMethodArguments) { Hub = hub; ServiceProvider = serviceProvider; @@ -40,12 +40,12 @@ namespace Microsoft.AspNetCore.SignalR /// The name of the Hub method being invoked. /// The arguments provided by the client. [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative is to use the other constructor.")] - public HubInvocationContext(HubCallerContext context, string hubMethodName, object[] hubMethodArguments) + public HubInvocationContext(HubCallerContext context, string hubMethodName, object?[] hubMethodArguments) { throw new NotSupportedException("This constructor no longer works. Use the other constructor."); } - internal HubInvocationContext(ObjectMethodExecutor objectMethodExecutor, HubCallerContext context, IServiceProvider serviceProvider, Hub hub, object[] hubMethodArguments) + internal HubInvocationContext(ObjectMethodExecutor objectMethodExecutor, HubCallerContext context, IServiceProvider serviceProvider, Hub hub, object?[] hubMethodArguments) : this(context, serviceProvider, hub, objectMethodExecutor.MethodInfo, hubMethodArguments) { ObjectMethodExecutor = objectMethodExecutor; @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.SignalR /// /// Gets the arguments provided by the client. /// - public IReadOnlyList HubMethodArguments { get; } + public IReadOnlyList HubMethodArguments { get; } /// /// The specific to the scope of this Hub method invocation. diff --git a/src/SignalR/server/Core/src/HubLifetimeManager.cs b/src/SignalR/server/Core/src/HubLifetimeManager.cs index 3022dd6286..a2f309d6a8 100644 --- a/src/SignalR/server/Core/src/HubLifetimeManager.cs +++ b/src/SignalR/server/Core/src/HubLifetimeManager.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.SignalR /// The invocation arguments. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous send. - public abstract Task SendAllAsync(string methodName, object[] args, CancellationToken cancellationToken = default); + public abstract Task SendAllAsync(string methodName, object?[]? args, CancellationToken cancellationToken = default); /// /// Sends an invocation message to all hub connections excluding the specified connections. @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.SignalR /// A collection of connection IDs to exclude. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous send. - public abstract Task SendAllExceptAsync(string methodName, object[] args, IReadOnlyList excludedConnectionIds, CancellationToken cancellationToken = default); + public abstract Task SendAllExceptAsync(string methodName, object?[]? args, IReadOnlyList excludedConnectionIds, CancellationToken cancellationToken = default); /// /// Sends an invocation message to the specified connection. @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.SignalR /// The invocation arguments. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous send. - public abstract Task SendConnectionAsync(string connectionId, string methodName, object[] args, CancellationToken cancellationToken = default); + public abstract Task SendConnectionAsync(string connectionId, string methodName, object?[]? args, CancellationToken cancellationToken = default); /// /// Sends an invocation message to the specified connections. @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.SignalR /// The invocation arguments. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous send. - public abstract Task SendConnectionsAsync(IReadOnlyList connectionIds, string methodName, object[] args, CancellationToken cancellationToken = default); + public abstract Task SendConnectionsAsync(IReadOnlyList connectionIds, string methodName, object?[]? args, CancellationToken cancellationToken = default); /// /// Sends an invocation message to the specified group. @@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.SignalR /// The invocation arguments. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous send. - public abstract Task SendGroupAsync(string groupName, string methodName, object[] args, CancellationToken cancellationToken = default); + public abstract Task SendGroupAsync(string groupName, string methodName, object?[]? args, CancellationToken cancellationToken = default); /// /// Sends an invocation message to the specified groups. @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.SignalR /// The invocation arguments. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous send. - public abstract Task SendGroupsAsync(IReadOnlyList groupNames, string methodName, object[] args, CancellationToken cancellationToken = default); + public abstract Task SendGroupsAsync(IReadOnlyList groupNames, string methodName, object?[]? args, CancellationToken cancellationToken = default); /// /// Sends an invocation message to the specified group excluding the specified connections. @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.SignalR /// A collection of connection IDs to exclude. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous send. - public abstract Task SendGroupExceptAsync(string groupName, string methodName, object[] args, IReadOnlyList excludedConnectionIds, CancellationToken cancellationToken = default); + public abstract Task SendGroupExceptAsync(string groupName, string methodName, object?[]? args, IReadOnlyList excludedConnectionIds, CancellationToken cancellationToken = default); /// /// Sends an invocation message to the specified user. @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.SignalR /// The invocation arguments. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous send. - public abstract Task SendUserAsync(string userId, string methodName, object[] args, CancellationToken cancellationToken = default); + public abstract Task SendUserAsync(string userId, string methodName, object?[]? args, CancellationToken cancellationToken = default); /// /// Sends an invocation message to the specified users. @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.SignalR /// The invocation arguments. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous send. - public abstract Task SendUsersAsync(IReadOnlyList userIds, string methodName, object[] args, CancellationToken cancellationToken = default); + public abstract Task SendUsersAsync(IReadOnlyList userIds, string methodName, object?[]? args, CancellationToken cancellationToken = default); /// /// Adds a connection to the specified group. diff --git a/src/SignalR/server/Core/src/HubOptions.cs b/src/SignalR/server/Core/src/HubOptions.cs index 5ff5df5045..a9a889909d 100644 --- a/src/SignalR/server/Core/src/HubOptions.cs +++ b/src/SignalR/server/Core/src/HubOptions.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.SignalR /// /// Gets or sets a collection of supported hub protocol names. /// - public IList SupportedProtocols { get; set; } = null; + public IList? SupportedProtocols { get; set; } /// /// Gets or sets the maximum message size of a single incoming hub message. The default is 32KB. @@ -52,6 +52,6 @@ namespace Microsoft.AspNetCore.SignalR /// public int? StreamBufferCapacity { get; set; } = null; - internal List HubFilters { get; set; } = null; + internal List? HubFilters { get; set; } } } diff --git a/src/SignalR/server/Core/src/HubOptionsSetup`T.cs b/src/SignalR/server/Core/src/HubOptionsSetup`T.cs index 26d55750de..a935980e09 100644 --- a/src/SignalR/server/Core/src/HubOptionsSetup`T.cs +++ b/src/SignalR/server/Core/src/HubOptionsSetup`T.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using Microsoft.Extensions.Options; @@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.SignalR public void Configure(HubOptions options) { // Do a deep copy, otherwise users modifying the HubOptions list would be changing the global options list - options.SupportedProtocols = new List(_hubOptions.SupportedProtocols); + options.SupportedProtocols = new List(_hubOptions.SupportedProtocols ?? Array.Empty()); options.KeepAliveInterval = _hubOptions.KeepAliveInterval; options.HandshakeTimeout = _hubOptions.HandshakeTimeout; options.ClientTimeoutInterval = _hubOptions.ClientTimeoutInterval; diff --git a/src/SignalR/server/Core/src/Hub`T.cs b/src/SignalR/server/Core/src/Hub`T.cs index f091b0c200..1a28a5bca4 100644 --- a/src/SignalR/server/Core/src/Hub`T.cs +++ b/src/SignalR/server/Core/src/Hub`T.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.SignalR.Internal; @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.SignalR /// The type of client. public abstract class Hub : Hub where T : class { - private IHubCallerClients _clients; + private IHubCallerClients? _clients; /// /// Gets or sets a that can be used to invoke methods on the clients connected to this hub. diff --git a/src/SignalR/server/Core/src/IClientProxy.cs b/src/SignalR/server/Core/src/IClientProxy.cs index e93ead6ec3..2b1884f950 100644 --- a/src/SignalR/server/Core/src/IClientProxy.cs +++ b/src/SignalR/server/Core/src/IClientProxy.cs @@ -23,6 +23,6 @@ namespace Microsoft.AspNetCore.SignalR /// A collection of arguments to pass to the client. /// The token to monitor for cancellation requests. The default value is . /// A that represents the asynchronous invoke. - Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default); + Task SendCoreAsync(string method, object?[]? args, CancellationToken cancellationToken = default); } } diff --git a/src/SignalR/server/Core/src/IHubFilter.cs b/src/SignalR/server/Core/src/IHubFilter.cs index baf754bb6c..35fcafeffc 100644 --- a/src/SignalR/server/Core/src/IHubFilter.cs +++ b/src/SignalR/server/Core/src/IHubFilter.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#nullable enable - using System; using System.Threading.Tasks; @@ -19,7 +17,7 @@ namespace Microsoft.AspNetCore.SignalR /// The context for the method invocation that holds all the important information about the invoke. /// The next filter to run, and for the final one, the Hub invocation. /// Returns the result of the Hub method invoke. - ValueTask InvokeMethodAsync(HubInvocationContext invocationContext, Func> next) => next(invocationContext); + ValueTask InvokeMethodAsync(HubInvocationContext invocationContext, Func> next) => next(invocationContext); /// /// Allows handling of the method. @@ -36,6 +34,6 @@ namespace Microsoft.AspNetCore.SignalR /// The exception, if any, for the connection closing. /// The next filter to run, and for the final one, the Hub invocation. /// - Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func next) => next(context, exception); + Task OnDisconnectedAsync(HubLifetimeContext context, Exception? exception, Func next) => next(context, exception); } } diff --git a/src/SignalR/server/Core/src/IHubProtocolResolver.cs b/src/SignalR/server/Core/src/IHubProtocolResolver.cs index b457c6e29b..1bccdcff7d 100644 --- a/src/SignalR/server/Core/src/IHubProtocolResolver.cs +++ b/src/SignalR/server/Core/src/IHubProtocolResolver.cs @@ -22,6 +22,6 @@ namespace Microsoft.AspNetCore.SignalR /// The protocol name. /// A collection of supported protocols. /// A matching or null if no matching protocol was found. - IHubProtocol GetProtocol(string protocolName, IReadOnlyList supportedProtocols); + IHubProtocol? GetProtocol(string protocolName, IReadOnlyList? supportedProtocols); } } diff --git a/src/SignalR/server/Core/src/IUserIdProvider.cs b/src/SignalR/server/Core/src/IUserIdProvider.cs index 9f7d540154..451d9184b6 100644 --- a/src/SignalR/server/Core/src/IUserIdProvider.cs +++ b/src/SignalR/server/Core/src/IUserIdProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.AspNetCore.SignalR @@ -14,6 +14,6 @@ namespace Microsoft.AspNetCore.SignalR /// /// The connection to get the user ID for. /// The user ID for the specified connection. - string GetUserId(HubConnectionContext connection); + string? GetUserId(HubConnectionContext connection); } -} \ No newline at end of file +} diff --git a/src/SignalR/server/Core/src/Internal/DefaultHubCallerContext.cs b/src/SignalR/server/Core/src/Internal/DefaultHubCallerContext.cs index 503e8110d3..d208ba6cbe 100644 --- a/src/SignalR/server/Core/src/Internal/DefaultHubCallerContext.cs +++ b/src/SignalR/server/Core/src/Internal/DefaultHubCallerContext.cs @@ -24,13 +24,13 @@ namespace Microsoft.AspNetCore.SignalR.Internal public override string ConnectionId => _connection.ConnectionId; /// - public override string UserIdentifier => _connection.UserIdentifier; + public override string? UserIdentifier => _connection.UserIdentifier; /// - public override ClaimsPrincipal User => _connection.User; + public override ClaimsPrincipal? User => _connection.User; /// - public override IDictionary Items => _connection.Items; + public override IDictionary Items => _connection.Items; /// public override IFeatureCollection Features => _connection.Features; diff --git a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.Log.cs b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.Log.cs index fb7e09cb4a..359c78f2db 100644 --- a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.Log.cs +++ b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.Log.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using Microsoft.AspNetCore.SignalR.Protocol; using Microsoft.Extensions.Internal; diff --git a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs index 8a040b7d92..889ee5dfc8 100644 --- a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs +++ b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/SignalR/server/Core/src/Internal/DefaultHubProtocolResolver.cs b/src/SignalR/server/Core/src/Internal/DefaultHubProtocolResolver.cs index 546a2f988b..605da56375 100644 --- a/src/SignalR/server/Core/src/Internal/DefaultHubProtocolResolver.cs +++ b/src/SignalR/server/Core/src/Internal/DefaultHubProtocolResolver.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _hubProtocols = _availableProtocols.Values.ToList(); } - public virtual IHubProtocol GetProtocol(string protocolName, IReadOnlyList supportedProtocols) + public virtual IHubProtocol? GetProtocol(string protocolName, IReadOnlyList? supportedProtocols) { protocolName = protocolName ?? throw new ArgumentNullException(nameof(protocolName)); @@ -49,10 +49,10 @@ namespace Microsoft.AspNetCore.SignalR.Internal private static class Log { // Category: DefaultHubProtocolResolver - private static readonly Action _registeredSignalRProtocol = + private static readonly Action _registeredSignalRProtocol = LoggerMessage.Define(LogLevel.Debug, new EventId(1, "RegisteredSignalRProtocol"), "Registered SignalR Protocol: {ProtocolName}, implemented by {ImplementationType}."); - private static readonly Action _foundImplementationForProtocol = + private static readonly Action _foundImplementationForProtocol = LoggerMessage.Define(LogLevel.Debug, new EventId(2, "FoundImplementationForProtocol"), "Found protocol implementation for requested protocol: {ProtocolName}."); public static void RegisteredSignalRProtocol(ILogger logger, string protocolName, Type implementationType) diff --git a/src/SignalR/server/Core/src/Internal/DynamicClientProxy.cs b/src/SignalR/server/Core/src/Internal/DynamicClientProxy.cs index 16e0ddd21d..9eda481fda 100644 --- a/src/SignalR/server/Core/src/Internal/DynamicClientProxy.cs +++ b/src/SignalR/server/Core/src/Internal/DynamicClientProxy.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Dynamic; @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _clientProxy = clientProxy; } - public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) + public override bool TryInvokeMember(InvokeMemberBinder binder, object?[]? args, out object? result) { result = _clientProxy.SendCoreAsync(binder.Name, args); return true; diff --git a/src/SignalR/server/Core/src/Internal/HubDispatcher.cs b/src/SignalR/server/Core/src/Internal/HubDispatcher.cs index 24e27ea1c2..29fecbda6f 100644 --- a/src/SignalR/server/Core/src/Internal/HubDispatcher.cs +++ b/src/SignalR/server/Core/src/Internal/HubDispatcher.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal internal abstract class HubDispatcher where THub : Hub { public abstract Task OnConnectedAsync(HubConnectionContext connection); - public abstract Task OnDisconnectedAsync(HubConnectionContext connection, Exception exception); + public abstract Task OnDisconnectedAsync(HubConnectionContext connection, Exception? exception); public abstract Task DispatchMessageAsync(HubConnectionContext connection, HubMessage hubMessage); public abstract IReadOnlyList GetParameterTypes(string name); } diff --git a/src/SignalR/server/Core/src/Internal/HubFilterFactory.cs b/src/SignalR/server/Core/src/Internal/HubFilterFactory.cs index 91a1b7fb71..70367c6d12 100644 --- a/src/SignalR/server/Core/src/Internal/HubFilterFactory.cs +++ b/src/SignalR/server/Core/src/Internal/HubFilterFactory.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#nullable enable - using System; using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; @@ -23,7 +21,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _filterType = filterType; } - public async ValueTask InvokeMethodAsync(HubInvocationContext invocationContext, Func> next) + public async ValueTask InvokeMethodAsync(HubInvocationContext invocationContext, Func> next) { var (filter, owned) = GetFilter(invocationContext.ServiceProvider); @@ -57,7 +55,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal } } - public async Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func next) + public async Task OnDisconnectedAsync(HubLifetimeContext context, Exception? exception, Func next) { var (filter, owned) = GetFilter(context.ServiceProvider); diff --git a/src/SignalR/server/Core/src/Internal/HubGroupList.cs b/src/SignalR/server/Core/src/Internal/HubGroupList.cs index af8dcf38fa..27026be6d8 100644 --- a/src/SignalR/server/Core/src/Internal/HubGroupList.cs +++ b/src/SignalR/server/Core/src/Internal/HubGroupList.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal private static readonly GroupConnectionList EmptyGroupConnectionList = new GroupConnectionList(); - public ConcurrentDictionary this[string groupName] + public ConcurrentDictionary? this[string groupName] { get { @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal internal class GroupConnectionList : ConcurrentDictionary { - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is ConcurrentDictionary list) { @@ -101,4 +101,4 @@ namespace Microsoft.AspNetCore.SignalR.Internal return base.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/src/SignalR/server/Core/src/Internal/HubMethodDescriptor.cs b/src/SignalR/server/Core/src/Internal/HubMethodDescriptor.cs index f868c2bcd7..f1ed20cb44 100644 --- a/src/SignalR/server/Core/src/Internal/HubMethodDescriptor.cs +++ b/src/SignalR/server/Core/src/Internal/HubMethodDescriptor.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/src/SignalR/server/Core/src/Internal/HubReflectionHelper.cs b/src/SignalR/server/Core/src/Internal/HubReflectionHelper.cs index a2fe4fa41c..e4b4a542e2 100644 --- a/src/SignalR/server/Core/src/Internal/HubReflectionHelper.cs +++ b/src/SignalR/server/Core/src/Internal/HubReflectionHelper.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal private static bool IsHubMethod(MethodInfo methodInfo) { - var baseDefinition = methodInfo.GetBaseDefinition().DeclaringType; + var baseDefinition = methodInfo.GetBaseDefinition().DeclaringType!; if (typeof(object) == baseDefinition || methodInfo.IsSpecialName) { return false; diff --git a/src/SignalR/server/Core/src/Internal/Proxies.cs b/src/SignalR/server/Core/src/Internal/Proxies.cs index 8a2beb26de..9f7d2197d4 100644 --- a/src/SignalR/server/Core/src/Internal/Proxies.cs +++ b/src/SignalR/server/Core/src/Internal/Proxies.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _userId = userId; } - public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default) + public Task SendCoreAsync(string method, object?[]? args, CancellationToken cancellationToken = default) { return _lifetimeManager.SendUserAsync(_userId, method, args, cancellationToken); } @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _userIds = userIds; } - public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default) + public Task SendCoreAsync(string method, object?[]? args, CancellationToken cancellationToken = default) { return _lifetimeManager.SendUsersAsync(_userIds, method, args, cancellationToken); } @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _groupName = groupName; } - public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default) + public Task SendCoreAsync(string method, object?[]? args, CancellationToken cancellationToken = default) { return _lifetimeManager.SendGroupAsync(_groupName, method, args, cancellationToken); } @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _groupNames = groupNames; } - public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default) + public Task SendCoreAsync(string method, object?[]? args, CancellationToken cancellationToken = default) { return _lifetimeManager.SendGroupsAsync(_groupNames, method, args, cancellationToken); } @@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _excludedConnectionIds = excludedConnectionIds; } - public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default) + public Task SendCoreAsync(string method, object?[]? args, CancellationToken cancellationToken = default) { return _lifetimeManager.SendGroupExceptAsync(_groupName, method, args, _excludedConnectionIds, cancellationToken); } @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _lifetimeManager = lifetimeManager; } - public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default) + public Task SendCoreAsync(string method, object?[]? args, CancellationToken cancellationToken = default) { return _lifetimeManager.SendAllAsync(method, args, cancellationToken); } @@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _excludedConnectionIds = excludedConnectionIds; } - public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default) + public Task SendCoreAsync(string method, object?[]? args, CancellationToken cancellationToken = default) { return _lifetimeManager.SendAllExceptAsync(method, args, _excludedConnectionIds, cancellationToken); } @@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _connectionId = connectionId; } - public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default) + public Task SendCoreAsync(string method, object?[]? args, CancellationToken cancellationToken = default) { return _lifetimeManager.SendConnectionAsync(_connectionId, method, args, cancellationToken); } @@ -154,7 +154,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal _connectionIds = connectionIds; } - public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default) + public Task SendCoreAsync(string method, object?[]? args, CancellationToken cancellationToken = default) { return _lifetimeManager.SendConnectionsAsync(_connectionIds, method, args, cancellationToken); } diff --git a/src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs b/src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs index b5a9a56d6e..1436963a47 100644 --- a/src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs +++ b/src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/src/SignalR/server/Core/src/Microsoft.AspNetCore.SignalR.Core.csproj b/src/SignalR/server/Core/src/Microsoft.AspNetCore.SignalR.Core.csproj index 385a449849..c5ae1cb371 100644 --- a/src/SignalR/server/Core/src/Microsoft.AspNetCore.SignalR.Core.csproj +++ b/src/SignalR/server/Core/src/Microsoft.AspNetCore.SignalR.Core.csproj @@ -6,6 +6,7 @@ true Microsoft.AspNetCore.SignalR false + enable diff --git a/src/SignalR/server/Core/src/SerializedHubMessage.cs b/src/SignalR/server/Core/src/SerializedHubMessage.cs index 8cd578b6a0..bbd979412f 100644 --- a/src/SignalR/server/Core/src/SerializedHubMessage.cs +++ b/src/SignalR/server/Core/src/SerializedHubMessage.cs @@ -14,13 +14,13 @@ namespace Microsoft.AspNetCore.SignalR { private SerializedMessage _cachedItem1; private SerializedMessage _cachedItem2; - private List _cachedItems; + private List? _cachedItems; private readonly object _lock = new object(); /// /// Gets the hub message for the serialization cache. /// - public HubMessage Message { get; } + public HubMessage? Message { get; } /// /// Initializes a new instance of the class. diff --git a/src/SignalR/server/Core/src/StreamTracker.cs b/src/SignalR/server/Core/src/StreamTracker.cs index 0df957d54b..fd0b525b0c 100644 --- a/src/SignalR/server/Core/src/StreamTracker.cs +++ b/src/SignalR/server/Core/src/StreamTracker.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable + using System; using System.Collections.Concurrent; using System.Collections.Generic;