diff --git a/src/Workspaces/Remote/Core/Serialization/MessagePackFormatters.cs b/src/Workspaces/Remote/Core/Serialization/MessagePackFormatters.cs index 2b6fc006a647d..01b96bb28e8e7 100644 --- a/src/Workspaces/Remote/Core/Serialization/MessagePackFormatters.cs +++ b/src/Workspaces/Remote/Core/Serialization/MessagePackFormatters.cs @@ -26,6 +26,7 @@ internal sealed class MessagePackFormatters { internal static readonly ImmutableArray Formatters = ImmutableArray.Create( ProjectIdFormatter.Instance, + EncodingFormatter.Instance, // ForceTypelessFormatter needs to be listed here for each Roslyn abstract type T that is being serialized OOP. // TODO: add a resolver that provides these https://github.com/dotnet/roslyn/issues/60724 new ForceTypelessFormatter(), @@ -34,8 +35,7 @@ internal sealed class MessagePackFormatters new ForceTypelessFormatter()); private static readonly ImmutableArray s_resolvers = ImmutableArray.Create( - StandardResolverAllowPrivate.Instance, - EncodingResolver.Instance); + StandardResolverAllowPrivate.Instance); internal static readonly IFormatterResolver DefaultResolver = CompositeResolver.Create(Formatters, s_resolvers); @@ -111,21 +111,15 @@ public void Serialize(ref MessagePackWriter writer, ProjectId? value, MessagePac } } - /// - /// Creates formatter for serialization. - /// - internal sealed class EncodingResolver : IFormatterResolver - { - public static readonly EncodingResolver Instance = new(); - - public IMessagePackFormatter? GetFormatter() - => typeof(T) == typeof(Encoding) ? (IMessagePackFormatter)(object)EncodingFormatter.Instance : null; - } - /// /// Supports (de)serialization of that do not customize or . /// The fallback will be discarded if the has any. /// + /// + /// Only supports (de)serializing values that are statically typed to . + /// This is important as we can't assume anything about arbitrary subtypes of + /// and can only return general from the deserializer. + /// internal sealed class EncodingFormatter : IMessagePackFormatter { public static readonly EncodingFormatter Instance = new();