Skip to content

Except for FormatterCache<Guid>, FormatterCache throws an exception in other situations #12

@if1live

Description

@if1live

I use MagicOnion with MagicOnion.Server.Redis.

this code works.

IMulticastSyncGroup<string, IUserHubReceiver> _group
    = groupProvider.GetOrAddSynchronousGroup<Guid, IUserHubReceiver>(name);
...
_group.Single(guid).OnMessage();

this code not works.

IMulticastSyncGroup<string, IUserHubReceiver> _group
    = groupProvider.GetOrAddSynchronousGroup<string, IUserHubReceiver>(name);
...
_group.Single("test").OnMessage();

stacktrace

Unhandled exception: Grpc.Core.RpcException: An error occurred while processing handler 'IUserHub/SendMessageAsync'.
System.TypeInitializationException: The type initializer for 'FormatterCache`1' threw an exception.
 ---> System.NotSupportedException: Specified method is not supported.
   at Cysharp.Runtime.Multicast.Distributed.Redis.KeyArrayFormatter`1.FormatterCache`1..cctor()
   --- End of inner exception stack trace ---
   at Cysharp.Runtime.Multicast.Distributed.Redis.KeyArrayFormatter`1.FormatterCache`1.get_Instance()
   at Cysharp.Runtime.Multicast.Distributed.Redis.RedisGroup`2.RedisPublishWriter.Write(ReadOnlyMemory`1 payload)
   at Cysharp.Runtime.Multicast.Remoting.RemoteProxyBase.Invoke[T1](String name, Int32 methodId, T1 arg1)
   at Wallaby_Shared_Hubs_IUserHubReceiver_Proxy.OnMessage(String)
   at Wallaby.Web.Hubs.UserGroupService.Send(String id, String message) in C:\dinkum-root\outback-wallaby\src\Wallaby.Web\Hubs\UserGroupService.cs:line 14
   at Wallaby.Web.Hubs.UserHub.SendMessageAsync(String message) in C:\dinkum-root\outback-wallaby\src\Wallaby.Web\Hubs\UserHub.cs:line 45

reason
https://github.com/Cysharp/Multicaster/blob/main/src/Multicaster.Distributed.Redis/KeyArrayFormatter.cs#L50

static FormatterCache()
{
    if (typeof(T) == typeof(Guid))
    {
        Instance = (IMessagePackFormatter<T>)(object)NativeGuidFormatter.Instance;
        return;
    }
    else
    {
        // TODO: Options
        Instance = (IMessagePackFormatter<T>)(object)(MessagePackSerializerOptions.Standard.Resolver.GetFormatter<T>() ?? throw new NotSupportedException());
    }
    throw new NotSupportedException();   // except GUID, reach here <----
}

Only GUID is allowed in FormatterCache.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions