Skip to content

Blazor: JSObjectReference ctor should take a IJSRuntime as input #26981

Answered by SteveSandersonMS
egil asked this question in General
Discussion options

You must be logged in to vote

Even though JSObjectReference is public, developers must use IJSObjectReference in order to get an object reference. That is:

jsRuntime.InvokeAsync<IJSObjectReference>(...); // Works
jsRuntime.InvokeAsync<JSObjectReference>(...); // Will not work (doesn't create an object reference)

The reason for this is in the implementation at https://github.com/dotnet/aspnetcore/blob/master/src/Shared/JSInterop/JSCallResultTypeHelper.cs. As you can see in the code there, we are looking for the interface type, not any other type (not even ones that implement the interface). Additionally, all the docs will only refer to IJSObjectReference, so developers don't have any reason to consider trying the concr…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

egil
Oct 16, 2020
Collaborator Author

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@egil
Comment options

egil Oct 19, 2020
Collaborator Author

@SteveSandersonMS
Comment options

@egil
Comment options

egil Oct 19, 2020
Collaborator Author

Answer selected by SteveSandersonMS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants