You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just what the title says. Known message pack formatters saved in formatter mapper is old making types like HashSet result in faulty generated code.
src/MagicOnion.Client.SourceGenerator/CodeAnalysis/SerializationFormatterNameMapper.cs:
This is the current code and as you see this does not contain HashSet formatter (might be missing other formatters as well but HashSet is the first one I noticed). This in turn makes the following code in the same file output invalid formatter type.
public bool TryMapGeneric(MagicOnionTypeInfo type, [NotNullWhen(true)] out string? formatterName, [NotNullWhen(true)] out string? formatterConstructorArgs)
{
formatterName = null;
formatterConstructorArgs = null;
var genericTypeArgs = string.Join(", ", type.GenericArguments.Select(x => x.FullName));
if (type is { Namespace: "MagicOnion", Name: "DynamicArgumentTuple" })
{
// MagicOnion.DynamicArgumentTuple
var ctorArguments = string.Join(", ", type.GenericArguments.Select(x => $"default({x.FullName})"));
formatterName = $"global::MagicOnion.Serialization.MessagePack.DynamicArgumentTupleFormatter<{genericTypeArgs}>";
formatterConstructorArgs = $"({ctorArguments})";
}
else if (MessagePackWellKnownSerializationTypes.Instance.GenericFormattersMap.TryGetValue(type.FullNameOpenType, out var mappedFormatterName))
{
// Well-known generic types (Nullable<T>, IList<T>, List<T>, Dictionary<TKey, TValue> ...)
formatterName = $"{mappedFormatterName}<{genericTypeArgs}>";
formatterConstructorArgs = "()";
}
else if (allowToMapUserDefinedFormatter)
{
// User-defined generic types
formatterName = $"{userDefinedFormatterNamespace}{(string.IsNullOrWhiteSpace(userDefinedFormatterNamespace) ? "" : ".")}{type.ToDisplayName(MagicOnionTypeInfo.DisplayNameFormat.Namespace | MagicOnionTypeInfo.DisplayNameFormat.WithoutGenericArguments)}Formatter<{genericTypeArgs}>";
formatterConstructorArgs = "()";
}
return formatterName != null;
}
For example having a service with return type UnaryTask<HashSet> will make the formatter created for MessagePackGeneratedGetFormatterHelper look like this:
case 6: return new global::MessagePack.Formatters.System.Collections.Generic.HashSetFormatter<global::System.UInt32>();
// Correct output would be this:
// case 6: return new global::MessagePack.Formatters.HashSetFormatter<global::System.UInt32>();
Adding missing formatters to MessagePackWellKnownSerializationTypes should fix the issue.
For those who are looking for a quick fix without waiting for an official fix, copy pasting messagepack formatters somewhere in your project accessible to the auto generated code should fix the problem. For example this code (copy pasted from messagepack with only namespace changed) will fix the above mentioned problem:
Just what the title says. Known message pack formatters saved in formatter mapper is old making types like HashSet result in faulty generated code.
src/MagicOnion.Client.SourceGenerator/CodeAnalysis/SerializationFormatterNameMapper.cs:
This is the current code and as you see this does not contain HashSet formatter (might be missing other formatters as well but HashSet is the first one I noticed). This in turn makes the following code in the same file output invalid formatter type.
For example having a service with return type UnaryTask<HashSet> will make the formatter created for MessagePackGeneratedGetFormatterHelper look like this:
Adding missing formatters to MessagePackWellKnownSerializationTypes should fix the issue.
For those who are looking for a quick fix without waiting for an official fix, copy pasting messagepack formatters somewhere in your project accessible to the auto generated code should fix the problem. For example this code (copy pasted from messagepack with only namespace changed) will fix the above mentioned problem:
The text was updated successfully, but these errors were encountered: