-
Notifications
You must be signed in to change notification settings - Fork 9.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
catch JS exceptions when using InvokeAsync and throw them in .NET #41916
Conversation
@@ -17,6 +17,20 @@ public JSObjectReferenceJsonConverterTest() | |||
JsonSerializerOptions = DefaultWebAssemblyJSRuntime.Instance.JsonSerializerOptions; | |||
} | |||
|
|||
[Fact] | |||
public void Read_ReadsJson_IJSObjectReference() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated bonus test.
a3e718f
to
b2fbddb
Compare
Thanks for your PR, @campersau. |
c720be5
to
b2886c7
Compare
Updated to also catch exceptions during |
d8728f4
to
19d99c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
19d99c5
to
a2a3350
Compare
Thanks @campersau! |
Hi @MackinnonBuck. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Hi is this PR actually online yet? I am using .NET 7 Blazor WebAssembly (7.0.202) and I still have this issue. The code runs fine if JS returns something but does not returns when JS returns public static async Task<T> GetGlobalObject<T>(this IJSRuntime js, string key) =>
await js.InvokeAsync<T>(
GetFullFuncName("getGlobalObj"),
key);
public static async Task<IJsWindowReference?> GetOpenerAsync(this IJSRuntime js)
{
var opener = await js.GetGlobalObject<IJSObjectReference?>("opener");
return opener?.AsWindow(js);
} getGlobalObj(key) {
return globalThis[key];
} |
Hi @datvm. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
catch JS exceptions when using InvokeAsync and throw them in .NET
Exceptions in
createJSCallResult
andstringifyArgs
were only thrown in JS before and .NET never received them.Examples of exceptions which are now reaching .NET:
aspnetcore/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts
Line 591 in 371bf37
aspnetcore/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts
Lines 167 to 188 in 371bf37
aspnetcore/src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts
Line 148 in 371bf37
Fixes #40272 (references the last exception from the list above)
Fixes #41934 (exception in
stringifyArgs
)