diff --git a/src/SignalR/common/Protocols.MessagePack/ref/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.netstandard2.0.cs b/src/SignalR/common/Protocols.MessagePack/ref/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.netstandard2.0.cs index ec222f2318..70f7ce9d02 100644 --- a/src/SignalR/common/Protocols.MessagePack/ref/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.netstandard2.0.cs +++ b/src/SignalR/common/Protocols.MessagePack/ref/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.netstandard2.0.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.SignalR public partial class MessagePackHubProtocolOptions { public MessagePackHubProtocolOptions() { } - public System.Collections.Generic.IList FormatterResolvers { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } + public System.Collections.Generic.IList FormatterResolvers { get { throw null; } set { } } } } namespace Microsoft.AspNetCore.SignalR.Protocol diff --git a/src/SignalR/common/Protocols.MessagePack/src/MessagePackHubProtocolOptions.cs b/src/SignalR/common/Protocols.MessagePack/src/MessagePackHubProtocolOptions.cs index 95ddfe6a9b..85025b6444 100644 --- a/src/SignalR/common/Protocols.MessagePack/src/MessagePackHubProtocolOptions.cs +++ b/src/SignalR/common/Protocols.MessagePack/src/MessagePackHubProtocolOptions.cs @@ -9,6 +9,25 @@ namespace Microsoft.AspNetCore.SignalR { public class MessagePackHubProtocolOptions { - public IList FormatterResolvers { get; set; } = MessagePackHubProtocol.CreateDefaultFormatterResolvers(); + private IList _formatterResolvers; + + public IList FormatterResolvers + { + get + { + if (_formatterResolvers == null) + { + // The default set of resolvers trigger a static constructor that throws on AOT environments. + // This gives users the chance to use an AOT friendly formatter. + _formatterResolvers = MessagePackHubProtocol.CreateDefaultFormatterResolvers(); + } + + return _formatterResolvers; + } + set + { + _formatterResolvers = value; + } + } } }