From c31cd34a59d530d4270c541393aaea69383dc241 Mon Sep 17 00:00:00 2001 From: TeBeCo Date: Thu, 19 Mar 2020 11:19:28 +0100 Subject: [PATCH 01/10] adding reference to MessagePackAnalyzer --- eng/Dependencies.props | 1 + eng/Versions.props | 1 + .../Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj | 1 + 3 files changed, 3 insertions(+) diff --git a/eng/Dependencies.props b/eng/Dependencies.props index ecee11a86fc0..976da28b3346 100644 --- a/eng/Dependencies.props +++ b/eng/Dependencies.props @@ -162,6 +162,7 @@ and are generated based on the last package release. + diff --git a/eng/Versions.props b/eng/Versions.props index f8574a574a93..db366167c5fd 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -225,6 +225,7 @@ 3.0.0 3.0.0 2.1.80 + 2.1.80 4.10.0 0.10.1 1.0.2 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 993bb94a5f30..e744a8f933e7 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 @@ -17,6 +17,7 @@ + From cd96510348f624c080a98b1f97ed141051b9a2a7 Mon Sep 17 00:00:00 2001 From: TeBeCo Date: Thu, 19 Mar 2020 11:51:45 +0100 Subject: [PATCH 02/10] add .ionide/ to the .gitignore/ (VsCode extensions for FSharp that triggers on sln/dotnet respo) --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 427adc718997..99e05dccb927 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ BenchmarkDotNet.Artifacts/ .gradle/ src/SignalR/clients/**/dist/ modules/ +.ionide/ # File extensions *.aps @@ -41,4 +42,4 @@ launchSettings.json msbuild.ProjectImports.zip StyleCop.Cache UpgradeLog.htm -.idea \ No newline at end of file +.idea From 4301c97603bc94adc6e213e37f7290befbbb62c9 Mon Sep 17 00:00:00 2001 From: TeBeCo Date: Thu, 19 Mar 2020 12:11:31 +0100 Subject: [PATCH 03/10] Update MessagePack and MessagePackAnalyzer from 2.1.80 to 2.1.90 see https://github.com/neuecc/MessagePack-CSharp/releases/tag/v2.1.90 --- eng/Versions.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index db366167c5fd..58e7b39c149c 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -224,8 +224,8 @@ 3.0.0 3.0.0 3.0.0 - 2.1.80 - 2.1.80 + 2.1.90 + 2.1.90 4.10.0 0.10.1 1.0.2 From 38813d3d14db6a8fabc60c3a150b7b4610c39b4f Mon Sep 17 00:00:00 2001 From: TeBeCo Date: Thu, 19 Mar 2020 12:25:20 +0100 Subject: [PATCH 04/10] add a .editorconfig specifically for src/SignalR/common/Protocols.MessagePack --- .../common/Protocols.MessagePack/src/.editorconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/SignalR/common/Protocols.MessagePack/src/.editorconfig diff --git a/src/SignalR/common/Protocols.MessagePack/src/.editorconfig b/src/SignalR/common/Protocols.MessagePack/src/.editorconfig new file mode 100644 index 000000000000..6b409a9a5dc9 --- /dev/null +++ b/src/SignalR/common/Protocols.MessagePack/src/.editorconfig @@ -0,0 +1,12 @@ +# EditorConfig is awesome:http://EditorConfig.org +# NOTE: Requires **VS2019 16.3** or later + +# New Rule Set +# Description: +# MsgPack001 : MsgPack001 Avoid static default for MessagePackSerializerOptions +# MsgPack002 : MsgPack002 Avoid using a mutable static value for MessagePackSerializerOptions + +# Code files +[*.{cs,vb}] +dotnet_diagnostic.MsgPack001.severity = error +dotnet_diagnostic.MsgPack002.severity = error From 9a81b491b127b76cdc86dbc22ac0d90a49968391 Mon Sep 17 00:00:00 2001 From: TeBeCo Date: Thu, 19 Mar 2020 14:14:44 +0100 Subject: [PATCH 05/10] re-use the same MsBuild variable to tie together versions of MessagePack and MessagePackAnalyzer --- eng/Dependencies.props | 2 +- eng/Versions.props | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/eng/Dependencies.props b/eng/Dependencies.props index 976da28b3346..c100f4529963 100644 --- a/eng/Dependencies.props +++ b/eng/Dependencies.props @@ -162,7 +162,7 @@ and are generated based on the last package release. - + diff --git a/eng/Versions.props b/eng/Versions.props index 58e7b39c149c..deee5bd4cfd7 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -225,7 +225,6 @@ 3.0.0 3.0.0 2.1.90 - 2.1.90 4.10.0 0.10.1 1.0.2 From 0737ecc65431733d594f4a15f86135eadbe352b5 Mon Sep 17 00:00:00 2001 From: TeBeCo Date: Thu, 19 Mar 2020 14:28:51 +0100 Subject: [PATCH 06/10] avoid leaking MessagePackAnalyzer as a transitive by specifying PrivateAssets="All" --- .../Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 e744a8f933e7..43f4873c800b 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 @@ -1,4 +1,4 @@ - + Implements the SignalR Hub Protocol over MsgPack. @@ -17,7 +17,7 @@ - + From d007ebd69f21717675257fca63671ef69945ce10 Mon Sep 17 00:00:00 2001 From: TeBeCo Date: Thu, 19 Mar 2020 18:21:38 +0100 Subject: [PATCH 07/10] Make _msgPackSerializerOptions readonly by using a local function in the MessagePackHubProtocol ctor --- .../src/Protocol/MessagePackHubProtocol.cs | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs index bd16161b0e63..6d6076681a0a 100644 --- a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs +++ b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs @@ -26,7 +26,7 @@ public class MessagePackHubProtocol : IHubProtocol private const int VoidResult = 2; private const int NonVoidResult = 3; - private MessagePackSerializerOptions _msgPackSerializerOptions; + private readonly MessagePackSerializerOptions _msgPackSerializerOptions; private static readonly string ProtocolName = "messagepack"; private static readonly int ProtocolVersion = 1; @@ -53,34 +53,41 @@ public MessagePackHubProtocol() public MessagePackHubProtocol(IOptions options) { var msgPackOptions = options.Value; - SetupResolver(msgPackOptions); - _msgPackSerializerOptions.WithSecurity(MessagePackSecurity.UntrustedData); - } + _msgPackSerializerOptions = SetupResolver(msgPackOptions); - private void SetupResolver(MessagePackHubProtocolOptions options) - { - // if counts don't match then we know users customized resolvers so we set up the options - // with the provided resolvers - if (options.FormatterResolvers.Count != SignalRResolver.Resolvers.Count) + MessagePackSerializerOptions SetupResolver(MessagePackHubProtocolOptions options) { - var resolver = CompositeResolver.Create(Array.Empty(), (IReadOnlyList)options.FormatterResolvers); - _msgPackSerializerOptions = MessagePackSerializerOptions.Standard.WithResolver(resolver); - return; - } + var resolver = SignalRResolver.Instance; + var hasCustomFormatterResovler = false; - for (var i = 0; i < options.FormatterResolvers.Count; i++) - { - // check if the user customized the resolvers - if (options.FormatterResolvers[i] != SignalRResolver.Resolvers[i]) + // if counts don't match then we know users customized resolvers so we set up the options with the provided resolvers + if (options.FormatterResolvers.Count != SignalRResolver.Resolvers.Count) { - var resolver = CompositeResolver.Create(Array.Empty(), (IReadOnlyList)options.FormatterResolvers); - _msgPackSerializerOptions = MessagePackSerializerOptions.Standard.WithResolver(resolver); - return; + hasCustomFormatterResovler = true; + } + else + { + //Compare each "reference" in the FormatterResolvers IList<> against the default "SignalRResolver.Resolvers" IList<> + for (var i = 0; i < options.FormatterResolvers.Count; i++) + { + // check if the user customized the resolvers + if (options.FormatterResolvers[i] != SignalRResolver.Resolvers[i]) + { + hasCustomFormatterResovler = true; + break; + } + } } - } - // Use optimized cached resolver if the default is chosen - _msgPackSerializerOptions = MessagePackSerializerOptions.Standard.WithResolver(SignalRResolver.Instance); + if (hasCustomFormatterResovler) + { + resolver = CompositeResolver.Create(Array.Empty(), (IReadOnlyList)options.FormatterResolvers); + } + + return MessagePackSerializerOptions.Standard + .WithResolver(resolver) + .WithSecurity(MessagePackSecurity.UntrustedData); + } } /// From 19c629ffd143a6a666c6a8912889156a595185de Mon Sep 17 00:00:00 2001 From: TeBeCo Date: Thu, 19 Mar 2020 18:33:43 +0100 Subject: [PATCH 08/10] Inline code from the local function inside the ctor itself --- .../src/Protocol/MessagePackHubProtocol.cs | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs index 6d6076681a0a..108b17a78108 100644 --- a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs +++ b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs @@ -53,41 +53,36 @@ public MessagePackHubProtocol() public MessagePackHubProtocol(IOptions options) { var msgPackOptions = options.Value; - _msgPackSerializerOptions = SetupResolver(msgPackOptions); + var resolver = SignalRResolver.Instance; + var hasCustomFormatterResovler = false; - MessagePackSerializerOptions SetupResolver(MessagePackHubProtocolOptions options) + // if counts don't match then we know users customized resolvers so we set up the options with the provided resolvers + if (msgPackOptions.FormatterResolvers.Count != SignalRResolver.Resolvers.Count) { - var resolver = SignalRResolver.Instance; - var hasCustomFormatterResovler = false; - - // if counts don't match then we know users customized resolvers so we set up the options with the provided resolvers - if (options.FormatterResolvers.Count != SignalRResolver.Resolvers.Count) - { - hasCustomFormatterResovler = true; - } - else + hasCustomFormatterResovler = true; + } + else + { + //Compare each "reference" in the FormatterResolvers IList<> against the default "SignalRResolver.Resolvers" IList<> + for (var i = 0; i < msgPackOptions.FormatterResolvers.Count; i++) { - //Compare each "reference" in the FormatterResolvers IList<> against the default "SignalRResolver.Resolvers" IList<> - for (var i = 0; i < options.FormatterResolvers.Count; i++) + // check if the user customized the resolvers + if (msgPackOptions.FormatterResolvers[i] != SignalRResolver.Resolvers[i]) { - // check if the user customized the resolvers - if (options.FormatterResolvers[i] != SignalRResolver.Resolvers[i]) - { - hasCustomFormatterResovler = true; - break; - } + hasCustomFormatterResovler = true; + break; } } + } - if (hasCustomFormatterResovler) - { - resolver = CompositeResolver.Create(Array.Empty(), (IReadOnlyList)options.FormatterResolvers); - } - - return MessagePackSerializerOptions.Standard - .WithResolver(resolver) - .WithSecurity(MessagePackSecurity.UntrustedData); + if (hasCustomFormatterResovler) + { + resolver = CompositeResolver.Create(Array.Empty(), (IReadOnlyList)msgPackOptions.FormatterResolvers); } + + _msgPackSerializerOptions = MessagePackSerializerOptions.Standard + .WithResolver(resolver) + .WithSecurity(MessagePackSecurity.UntrustedData); } /// From f1161af6f8688d27a6d08220e47e9b8e6aa8ab82 Mon Sep 17 00:00:00 2001 From: TeBeCo Date: Thu, 19 Mar 2020 18:56:34 +0100 Subject: [PATCH 09/10] =?UTF-8?q?fix=20typo=20=F0=9F=A6=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Protocol/MessagePackHubProtocol.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs index 108b17a78108..597b0ed6bf86 100644 --- a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs +++ b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs @@ -54,12 +54,12 @@ public MessagePackHubProtocol(IOptions options) { var msgPackOptions = options.Value; var resolver = SignalRResolver.Instance; - var hasCustomFormatterResovler = false; + var hasCustomFormatterResolver = false; // if counts don't match then we know users customized resolvers so we set up the options with the provided resolvers if (msgPackOptions.FormatterResolvers.Count != SignalRResolver.Resolvers.Count) { - hasCustomFormatterResovler = true; + hasCustomFormatterResolver = true; } else { @@ -69,13 +69,13 @@ public MessagePackHubProtocol(IOptions options) // check if the user customized the resolvers if (msgPackOptions.FormatterResolvers[i] != SignalRResolver.Resolvers[i]) { - hasCustomFormatterResovler = true; + hasCustomFormatterResolver = true; break; } } } - if (hasCustomFormatterResovler) + if (hasCustomFormatterResolver) { resolver = CompositeResolver.Create(Array.Empty(), (IReadOnlyList)msgPackOptions.FormatterResolvers); } From 5c9a35dc17e9013c51c1c1827e14a80aa4c35997 Mon Sep 17 00:00:00 2001 From: Brennan Date: Thu, 19 Mar 2020 14:35:42 -0700 Subject: [PATCH 10/10] Update src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs --- .../src/Protocol/MessagePackHubProtocol.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs index 597b0ed6bf86..e1a762937bae 100644 --- a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs +++ b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs @@ -63,7 +63,7 @@ public MessagePackHubProtocol(IOptions options) } else { - //Compare each "reference" in the FormatterResolvers IList<> against the default "SignalRResolver.Resolvers" IList<> + // Compare each "reference" in the FormatterResolvers IList<> against the default "SignalRResolver.Resolvers" IList<> for (var i = 0; i < msgPackOptions.FormatterResolvers.Count; i++) { // check if the user customized the resolvers