Skip to content

Commit

Permalink
RemotingSession shouldn't overwrite the serialized exception with an …
Browse files Browse the repository at this point in the history
…empty MessageCallResult message.
  • Loading branch information
yallie committed Nov 19, 2024
1 parent 59320ff commit 2c6ea75
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
11 changes: 7 additions & 4 deletions CoreRemoting.Tests/RpcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ public void Error_method_throws_Exception()
client.Connect();

var proxy = client.CreateProxy<ITestService>();
var ex = Assert.Throws<Exception>(() => proxy.Error(nameof(Error_method_throws_Exception)));
var ex = Assert.Throws<RemoteInvocationException>(() =>
proxy.Error(nameof(Error_method_throws_Exception)))
.GetInnermostException();

Assert.NotNull(ex);
Assert.Equal(nameof(Error_method_throws_Exception), ex.Message);
Expand Down Expand Up @@ -453,10 +455,11 @@ public async Task ErrorAsync_method_throws_Exception()
client.Connect();

var proxy = client.CreateProxy<ITestService>();
var ex = await Assert.ThrowsAsync<Exception>(async () =>
await proxy.ErrorAsync(nameof(ErrorAsync_method_throws_Exception)));
var ex = (await Assert.ThrowsAsync<RemoteInvocationException>(async () =>
await proxy.ErrorAsync(nameof(ErrorAsync_method_throws_Exception))))
.GetInnermostException();

Assert.NotNull(ex);
Assert.NotNull(ex);
Assert.Equal(nameof(ErrorAsync_method_throws_Exception), ex.Message);
}
finally
Expand Down
14 changes: 14 additions & 0 deletions CoreRemoting.Tests/Tools/ExceptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace CoreRemoting.Tests.Tools;

public static class ExceptionExtensions
{
public static Exception GetInnermostException(this Exception ex)
{
while (ex?.InnerException != null)
ex = ex.InnerException;

return ex;
}
}
8 changes: 6 additions & 2 deletions CoreRemoting/RemotingSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,12 @@ private void ProcessRpcMessage(WireMessage request)
if (oneWay)
return;

serializedResult =
_server.Serializer.Serialize(serverRpcContext.MethodCallResultMessage);
// don't overwrite the serialized exception
if (ReferenceEquals(serializedResult, Array.Empty<byte>()))
{
serializedResult =
_server.Serializer.Serialize(serverRpcContext.MethodCallResultMessage);
}
}

var methodResultMessage =
Expand Down

0 comments on commit 2c6ea75

Please sign in to comment.