Throw clear error when invoking async JSInvokable method synchronously - #68789
Open
SergioAlmeida29 wants to merge 2 commits into
Open
Throw clear error when invoking async JSInvokable method synchronously#68789SergioAlmeida29 wants to merge 2 commits into
SergioAlmeida29 wants to merge 2 commits into
Conversation
Calling an async Task- or ValueTask-returning [JSInvokable] method via the synchronous invokeMethod path serialized the live task instance, producing confusing JSON serialization errors, or silently returning meaningless state for a non-generic ValueTask. DotNetDispatcher.Invoke now detects these results and throws an InvalidOperationException naming the method and directing to invokeMethodAsync. The asynchronous dispatch path is unaffected. Fixes dotnet#46811 Signed-off-by: Sergio Almeida <sergioalmeida29.05@gmail.com>
Contributor
|
Thanks for your PR, @SergioAlmeida29. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Author
|
@dotnet-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the changes (Less than 80 chars)
Throw clear error when invoking async JSInvokable methods synchronously
Description
Calling a
Task- orValueTask<T>-returning[JSInvokable]method via synchronousinvokeMethodserialized the live task instance, producing confusing JSON serialization errors (or meaningless JSON for non-genericValueTask).DotNetDispatcher.Invokenow detects these results and throws anInvalidOperationExceptionnaming the method and directing toinvokeMethodAsync. The async dispatch path (BeginInvokeDotNet) is unaffected. Tests cover void /Task/Task<T>× sync / async invokers.Fixes #46811