2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
4
using System ;
5
- using System . Runtime . ExceptionServices ;
6
5
using System . Text . Json ;
7
6
using Microsoft . AspNetCore . SignalR ;
8
7
using Microsoft . Extensions . Logging ;
9
8
using Microsoft . Extensions . Options ;
10
9
using Microsoft . JSInterop ;
10
+ using Microsoft . JSInterop . Infrastructure ;
11
11
12
12
namespace Microsoft . AspNetCore . Components . Server . Circuits
13
13
{
@@ -30,28 +30,34 @@ internal void Initialize(CircuitClientProxy clientProxy)
30
30
_clientProxy = clientProxy ?? throw new ArgumentNullException ( nameof ( clientProxy ) ) ;
31
31
}
32
32
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 )
34
34
{
35
- if ( ! success )
35
+ if ( ! invocationResult . Success )
36
36
{
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
+
39
40
if ( _options . DetailedErrors )
40
41
{
41
- EndInvokeDotNetCore ( callId , success , actualException . ToString ( ) ) ;
42
+ errorMessage = invocationResult . Exception . ToString ( ) ;
42
43
}
43
44
else
44
45
{
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
+ }
47
51
48
- EndInvokeDotNetCore ( callId , success , message ) ;
52
+ errorMessage += $ ". For more details turn on detailed exceptions in ' { nameof ( CircuitOptions ) } . { nameof ( CircuitOptions . DetailedErrors ) } '" ;
49
53
}
54
+
55
+ EndInvokeDotNetCore ( invocationInfo . CallId , success : false , errorMessage ) ;
50
56
}
51
57
else
52
58
{
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 ) ;
55
61
}
56
62
}
57
63
@@ -113,27 +119,27 @@ public static class Log
113
119
internal static void BeginInvokeJS ( ILogger logger , long asyncHandle , string identifier ) =>
114
120
_beginInvokeJS ( logger , asyncHandle , identifier , null ) ;
115
121
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 )
117
123
{
118
- if ( assemblyName != null )
124
+ if ( invocationInfo . AssemblyName != null )
119
125
{
120
- _invokeStaticDotNetMethodException ( logger , assemblyName , methodIdentifier , callId , exception ) ;
126
+ _invokeStaticDotNetMethodException ( logger , invocationInfo . AssemblyName , invocationInfo . MethodIdentifier , invocationInfo . CallId , exception ) ;
121
127
}
122
128
else
123
129
{
124
- _invokeInstanceDotNetMethodException ( logger , methodIdentifier , dotNetObjectReference , callId , exception ) ;
130
+ _invokeInstanceDotNetMethodException ( logger , invocationInfo . MethodIdentifier , invocationInfo . DotNetObjectId , invocationInfo . CallId , exception ) ;
125
131
}
126
132
}
127
133
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 )
129
135
{
130
- if ( assemblyName != null )
136
+ if ( invocationInfo . AssemblyName != null )
131
137
{
132
- _invokeStaticDotNetMethodSuccess ( logger , assemblyName , methodIdentifier , callId , null ) ;
138
+ _invokeStaticDotNetMethodSuccess ( logger , invocationInfo . AssemblyName , invocationInfo . MethodIdentifier , invocationInfo . CallId , null ) ;
133
139
}
134
140
else
135
141
{
136
- _invokeInstanceDotNetMethodSuccess ( logger , methodIdentifier , dotNetObjectId , callId , null ) ;
142
+ _invokeInstanceDotNetMethodSuccess ( logger , invocationInfo . MethodIdentifier , invocationInfo . DotNetObjectId , invocationInfo . CallId , null ) ;
137
143
}
138
144
139
145
}
0 commit comments