Cysharp / MagicOnion

Unified Realtime/API framework for .NET platform and Unity.
MIT License
3.68k stars 417 forks source link

Serialize DynamicArgumentTuple<int, int, int> exception in MagicOnion + MemoryPack #686

Closed 0x5143 closed 3 weeks ago

0x5143 commented 8 months ago

Env: MagicOnion + MemoryPack Ver: 5.1.8 Client: Unity 2021.3.12f1 Server: .NET 7.0 x64 Method:

Task Test3Async(int a, int b, int c);

Serialize exception:

fail: MagicOnion.Server.MethodHandler[91]
      A hub method handler throws an exception occurred in IChatHub/Test3Async
      MemoryPack.MemoryPackSerializationException: Sequence reached end, reader can not provide more buffer.
         at MemoryPack.MemoryPackSerializationException.ThrowSequenceReachedEnd()
         at MemoryPack.MemoryPackReader.GetNextSpan(Int32 sizeHint)
         at MemoryPack.Formatters.DangerousUnmanagedFormatter`1.Deserialize(MemoryPackReader& reader, T& value)
         at MemoryPack.MemoryPackSerializer.Deserialize[T](ReadOnlySequence`1& buffer, T& value, MemoryPackSerializerOptions options)
         at MemoryPack.MemoryPackSerializer.Deserialize[T](ReadOnlySequence`1& buffer, MemoryPackSerializerOptions options)
         at MagicOnion.Serialization.MemoryPack.MemoryPackMagicOnionSerializerProvider.MagicOnionSerializer.Deserialize[T](ReadOnlySequence`1& bytes) in E:\Projects\GitHub\MagicOnion\src\MagicOnion.Serialization.MemoryPack\MemoryPackMagicOnionSerializer.cs:line 45
         at MagicOnion.Serialization.MemoryPack.MemoryPackMagicOnionSerializerProvider.MagicOnionSerializer.MagicOnion.Serialization.IMagicOnionSerializer.Deserialize[T](ReadOnlySequence`1& bytes)
         at MagicOnion.Server.Hubs.StreamingHubMethodInvoker.StreamingHubMethodInvokerTask`1.InvokeAsync(StreamingHubContext context) in E:\Projects\GitHub\MagicOnion\src\MagicOnion.Server\Hubs\StreamingHubHandler.cs:line 157
         at MagicOnion.Server.Hubs.StreamingHubBase`2.HandleMessageAsync() in E:\Projects\GitHub\MagicOnion\src\MagicOnion.Server\Hubs\StreamingHub.cs:line 184

The following function works fine:

Task Test1Async(int a);
Task Test2Async(int a, int b);
0x5143 commented 8 months ago
var abc1 = Unsafe.SizeOf<DynamicArgumentTuple<int, int>>();
var abc2 = Unsafe.SizeOf<DynamicArgumentTuple<int, int, int>>();
var abc3 = Unsafe.SizeOf<DynamicArgumentTuple<int, int, int, int>>();
var abc4 = Unsafe.SizeOf<DynamicArgumentTuple<int, int, int, int, int>>();
var abc5 = Unsafe.SizeOf<DynamicArgumentTuple<int, int, int, int, int, int>>();

Windows 10 x64 ASP.NET Result: 8, 16, 16, 24, 24 Unity 2021.3.12f1 Result: 8, 12, 16, 20, 24

0x5143 commented 7 months ago

Modified ASP.NET .csproj will fixed this:

<PlatformTarget>x86</PlatformTarget>
github-actions[bot] commented 1 month ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.