Repository navigation
Fix misleading error for synchronous async JS interop calls - #69659
Open
shantanu2002git wants to merge 2 commits into
Open
shantanu2002git wants to merge 2 commits into
shantanu2002git wants to merge 2 commits into
Conversation
Contributor
|
Thanks for your PR, @shantanu2002git. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Author
|
@dotnet-policy-service agree |
1 task done
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The regression test does not verify that the asynchronous target method remains uninvoked.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Improves synchronous JS interop diagnostics when targeting asynchronous .NET methods.
Changes:
- Detects
TaskandValueTaskreturn types before invocation. - Adds regression coverage for generic and non-generic variants.
| File | Description |
|---|---|
DotNetDispatcher.cs |
Rejects synchronous calls to asynchronous methods. |
DotNetDispatcherTest.cs |
Tests the new diagnostic across supported async types. |
Comment on lines
+115
to
+116
| var exception = Assert.Throws<InvalidOperationException>(() => | ||
| DotNetDispatcher.Invoke(jsRuntime, new DotNetInvocationInfo(null, methodIdentifier, targetReference.ObjectId, default), argsJson)); |
Contributor
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
|
Commenter does not have sufficient privileges for PR 69659 in repo dotnet/aspnetcore |
This was referenced Nov 20, 2026
Closed
This branch has not been deployed
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)
Fix misleading error for synchronous async JS interop calls
Description
Fixes #46811.
When a
[JSInvokable]method returningTask,Task<T>,ValueTask, orValueTask<T>is invoked synchronously from JavaScript, the synchronous dispatcher previously attempted to serialize the returned asynchronous value, resulting in a misleading serialization error.This change detects asynchronous return types before invoking the method and throws a clear
InvalidOperationExceptiondirecting callers to useinvokeMethodAsync.The existing asynchronous JS interop path is unchanged.
Changes
TaskandValueTaskreturn types in the synchronous dispatcher.TaskandValueTaskreturn types.Testing
DotNetDispatcherTest: 67 passed, 0 failedMicrosoft.JSInterop.Tests: 174 passed, 0 failedFixes #46811