Skip to content

Commit f69417d

Browse files
committed
React to breaking changes
1 parent e10969f commit f69417d

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

src/Components/Server/src/Circuits/CircuitHost.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ public async Task BeginInvokeDotNetFromJS(string callId, string assemblyName, st
339339
await Renderer.Dispatcher.InvokeAsync(() =>
340340
{
341341
Log.BeginInvokeDotNet(_logger, callId, assemblyName, methodIdentifier, dotNetObjectId);
342-
DotNetDispatcher.BeginInvokeDotNet(JSRuntime, callId, assemblyName, methodIdentifier, dotNetObjectId, argsJson);
342+
var invocationInfo = new DotNetInvocationInfo(assemblyName, methodIdentifier, dotNetObjectId, callId);
343+
DotNetDispatcher.BeginInvokeDotNet(JSRuntime, invocationInfo, argsJson);
343344
});
344345
}
345346
catch (Exception ex)

src/Components/Server/src/Circuits/RemoteJSRuntime.cs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Runtime.ExceptionServices;
65
using System.Text.Json;
76
using Microsoft.AspNetCore.SignalR;
87
using Microsoft.Extensions.Logging;
98
using Microsoft.Extensions.Options;
109
using Microsoft.JSInterop;
10+
using Microsoft.JSInterop.Infrastructure;
1111

1212
namespace Microsoft.AspNetCore.Components.Server.Circuits
1313
{
@@ -30,28 +30,34 @@ internal void Initialize(CircuitClientProxy clientProxy)
3030
_clientProxy = clientProxy ?? throw new ArgumentNullException(nameof(clientProxy));
3131
}
3232

33-
protected override void EndInvokeDotNet(string callId, bool success, object resultOrError, string assemblyName, string methodIdentifier, long dotNetObjectId)
33+
protected override void EndInvokeDotNet(DotNetInvocationInfo invocationInfo, in DotNetInvocationResult invocationResult)
3434
{
35-
if (!success)
35+
if (!invocationResult.Success)
3636
{
37-
var actualException = resultOrError is Exception ex ? ex : resultOrError is ExceptionDispatchInfo edi ? edi.SourceException : resultOrError;
38-
Log.InvokeDotNetMethodException(_logger, callId, assemblyName, methodIdentifier, dotNetObjectId, actualException as Exception);
37+
Log.InvokeDotNetMethodException(_logger, invocationInfo, invocationResult.Exception);
38+
string errorMessage;
39+
3940
if (_options.DetailedErrors)
4041
{
41-
EndInvokeDotNetCore(callId, success, actualException.ToString());
42+
errorMessage = invocationResult.Exception.ToString();
4243
}
4344
else
4445
{
45-
var message = $"There was an exception invoking '{methodIdentifier}' on assembly '{assemblyName}'. For more details turn on " +
46-
$"detailed exceptions in '{typeof(CircuitOptions).Name}.{nameof(CircuitOptions.DetailedErrors)}'";
46+
errorMessage = $"There was an exception invoking '{invocationInfo.MethodIdentifier}'";
47+
if (invocationInfo.AssemblyName != null)
48+
{
49+
errorMessage += $" on assembly '{invocationInfo.AssemblyName}'";
50+
}
4751

48-
EndInvokeDotNetCore(callId, success, message);
52+
errorMessage += $". For more details turn on detailed exceptions in '{nameof(CircuitOptions)}.{nameof(CircuitOptions.DetailedErrors)}'";
4953
}
54+
55+
EndInvokeDotNetCore(invocationInfo.CallId, success: false, errorMessage);
5056
}
5157
else
5258
{
53-
Log.InvokeDotNetMethodSuccess(_logger, callId, assemblyName, methodIdentifier, dotNetObjectId);
54-
EndInvokeDotNetCore(callId, success, resultOrError);
59+
Log.InvokeDotNetMethodSuccess(_logger, invocationInfo);
60+
EndInvokeDotNetCore(invocationInfo.CallId, success: true, invocationResult.Result);
5561
}
5662
}
5763

@@ -113,27 +119,27 @@ public static class Log
113119
internal static void BeginInvokeJS(ILogger logger, long asyncHandle, string identifier) =>
114120
_beginInvokeJS(logger, asyncHandle, identifier, null);
115121

116-
internal static void InvokeDotNetMethodException(ILogger logger, string callId, string assemblyName, string methodIdentifier, long dotNetObjectReference, Exception exception)
122+
internal static void InvokeDotNetMethodException(ILogger logger, in DotNetInvocationInfo invocationInfo , Exception exception)
117123
{
118-
if (assemblyName != null)
124+
if (invocationInfo.AssemblyName != null)
119125
{
120-
_invokeStaticDotNetMethodException(logger, assemblyName, methodIdentifier, callId, exception);
126+
_invokeStaticDotNetMethodException(logger, invocationInfo.AssemblyName, invocationInfo.MethodIdentifier, invocationInfo.CallId, exception);
121127
}
122128
else
123129
{
124-
_invokeInstanceDotNetMethodException(logger, methodIdentifier, dotNetObjectReference, callId, exception);
130+
_invokeInstanceDotNetMethodException(logger, invocationInfo.MethodIdentifier, invocationInfo.DotNetObjectId, invocationInfo.CallId, exception);
125131
}
126132
}
127133

128-
internal static void InvokeDotNetMethodSuccess(ILogger<RemoteJSRuntime> logger, string callId, string assemblyName, string methodIdentifier, long dotNetObjectId)
134+
internal static void InvokeDotNetMethodSuccess(ILogger<RemoteJSRuntime> logger, in DotNetInvocationInfo invocationInfo)
129135
{
130-
if (assemblyName != null)
136+
if (invocationInfo.AssemblyName != null)
131137
{
132-
_invokeStaticDotNetMethodSuccess(logger, assemblyName, methodIdentifier, callId, null);
138+
_invokeStaticDotNetMethodSuccess(logger, invocationInfo.AssemblyName, invocationInfo.MethodIdentifier, invocationInfo.CallId, null);
133139
}
134140
else
135141
{
136-
_invokeInstanceDotNetMethodSuccess(logger, methodIdentifier, dotNetObjectId, callId, null);
142+
_invokeInstanceDotNetMethodSuccess(logger, invocationInfo.MethodIdentifier, invocationInfo.DotNetObjectId, invocationInfo.CallId, null);
137143
}
138144

139145
}

src/Components/test/E2ETest/ServerExecutionTests/InteropReliabilityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public async Task CannotInvokeJSInvokableMethodsWithWrongReferenceId()
195195
var expectedDotNetObjectRef = "[\"1\",true,{\"__dotNetObject\":1}]";
196196
var expectedError = "[\"1\"," +
197197
"false," +
198-
"\"There was an exception invoking \\u0027Reverse\\u0027 on assembly \\u0027\\u0027. For more details turn on detailed exceptions in \\u0027CircuitOptions.DetailedErrors\\u0027\"]";
198+
"\"There was an exception invoking \\u0027Reverse\\u0027. For more details turn on detailed exceptions in \\u0027CircuitOptions.DetailedErrors\\u0027\"]";
199199

200200
await GoToTestComponent(Batches);
201201

0 commit comments

Comments
 (0)