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 diff --git a/eng/Dependencies.props b/eng/Dependencies.props index ecee11a86fc0..c100f4529963 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..deee5bd4cfd7 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -224,7 +224,7 @@ 3.0.0 3.0.0 3.0.0 - 2.1.80 + 2.1.90 4.10.0 0.10.1 1.0.2 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 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..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,6 +17,7 @@ + diff --git a/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs b/src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs index bd16161b0e63..e1a762937bae 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,36 @@ public MessagePackHubProtocol() public MessagePackHubProtocol(IOptions options) { var msgPackOptions = options.Value; - SetupResolver(msgPackOptions); - _msgPackSerializerOptions.WithSecurity(MessagePackSecurity.UntrustedData); - } + var resolver = SignalRResolver.Instance; + var hasCustomFormatterResolver = false; - 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) + // 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 = CompositeResolver.Create(Array.Empty(), (IReadOnlyList)options.FormatterResolvers); - _msgPackSerializerOptions = MessagePackSerializerOptions.Standard.WithResolver(resolver); - return; + hasCustomFormatterResolver = true; } - - for (var i = 0; i < options.FormatterResolvers.Count; i++) + else { - // check if the user customized the resolvers - if (options.FormatterResolvers[i] != SignalRResolver.Resolvers[i]) + // Compare each "reference" in the FormatterResolvers IList<> against the default "SignalRResolver.Resolvers" IList<> + for (var i = 0; i < msgPackOptions.FormatterResolvers.Count; i++) { - var resolver = CompositeResolver.Create(Array.Empty(), (IReadOnlyList)options.FormatterResolvers); - _msgPackSerializerOptions = MessagePackSerializerOptions.Standard.WithResolver(resolver); - return; + // check if the user customized the resolvers + if (msgPackOptions.FormatterResolvers[i] != SignalRResolver.Resolvers[i]) + { + hasCustomFormatterResolver = true; + break; + } } } - // Use optimized cached resolver if the default is chosen - _msgPackSerializerOptions = MessagePackSerializerOptions.Standard.WithResolver(SignalRResolver.Instance); + if (hasCustomFormatterResolver) + { + resolver = CompositeResolver.Create(Array.Empty(), (IReadOnlyList)msgPackOptions.FormatterResolvers); + } + + _msgPackSerializerOptions = MessagePackSerializerOptions.Standard + .WithResolver(resolver) + .WithSecurity(MessagePackSecurity.UntrustedData); } ///