Cysharp / MagicOnion

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

Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. MessagePackSerializationException: Failed to deserialize System.Int32 value. #664

Closed rayshow9527 closed 3 months ago

rayshow9527 commented 12 months ago

I'm trying to return a model in response but get below exception, can someone help look into this issue?

server side code:

public async UnaryResult<TestModel> TestFunctionAsync(TestModel a)
        {
            var response = new TestModel()
            {
                X = a.X,
                Y = a.Y
            };

            return response;
        }
    [MessagePackObject]
    public class TestModel
    {
        [Key(0)]
        public int X { get; set; }
        [Key(1)]
        public int Y { get; set; }
    }

client side code:

        public async Task<ActionResult> TestAsync()
        {

            var channel = GrpcChannel.ForAddress("https://localhost:5001");

            // Create a proxy to call the server transparently.
            var client = MagicOnionClient.Create<IMyFirstService>(channel);

            // Call the server-side method using the proxy.
            var result = await client .TestFunctionAsync(new TestModel()
            {
                X = 123,
                Y = 234
            });

            Console.WriteLine($"Result: {result}");

            return Ok(true);
        }

Exception message: Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. MessagePackSerializationException: Failed to deserialize System.Int32 value. MessagePackSerializationException: Unexpected msgpack code 146 (fixarray) encountered.", DebugException="MessagePack.MessagePackSerializationException: Failed to deserialize System.Int32 value. ---> MessagePack.MessagePackSerializationException: Unexpected msgpack code 146 (fixarray) encountered. at MessagePack.MessagePackReader.ThrowInvalidCode(Byte code) at MessagePack.MessagePackReader.ReadInt32() at MessagePack.MessagePackSerializer.Deserialize[T](MessagePackReader& reader, MessagePackSerializerOptions options) --- End of inner exception stack trace --- at MessagePack.MessagePackSerializer.Deserialize[T](MessagePackReader& reader, MessagePackSerializerOptions options) at MessagePack.MessagePackSerializer.Deserialize[T](ReadOnlySequence1& byteSequence, MessagePackSerializerOptions options, CancellationToken cancellationToken) at MagicOnion.Serialization.MessagePackMagicOnionSerializerProvider.MessagePackMagicOnionSerializer.MagicOnion.Serialization.IMagicOnionSerializer.Deserialize[T](ReadOnlySequence1& bytes) at MagicOnion.GrpcMethodHelper.<>cDisplayClass9_01.<CreateBoxedMarshaller>b__1(DeserializationContext ctx) at Grpc.Net.Client.StreamExtensions.ReadMessageAsync[TResponse](Stream responseStream, GrpcCall call, Func2 deserializer, String grpcEncoding, Boolean singleMessage, CancellationToken cancellationToken) at Grpc.Net.Client.Internal.GrpcCall2.RunCall(HttpRequestMessage request, Nullable1 timeout)") at MagicOnion.Client.ResponseContextRaw2.FromRawResponseToResponseAsync() at MagicOnion.UnaryResult1.UnwrapResponse() at BenchmarkWebClientTest.Controllers.BenchmarkController.TestLog() in C:\SourceCode\others\MagicOnionClientTest\BenchmarkWebClientTest\Controllers\BenchmarkController.cs:line 76 at lambda_method5(Closure , Object ) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.gAwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

mayuki commented 10 months ago

We were unable to reproduce this issue. It's possible that the type definition may differ between the client and server.

github-actions[bot] commented 4 months 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.