Warm tip: This article is reproduced from serverfault.com, please click

The type or namespace IJSObjectReference could not be found

发布于 2020-11-29 19:52:18

I just started Blazor. I am trying to invoke a javascript function from a razor partial class.

using Microsoft.JSInterop;
public partial class Counter
{
    [Inject] IJSRuntime js { get; set; }
    IJSObjectReference module;

    [JSInvokable]
    public async Task IncrementCount()
    {
        module = await js.InvokeAsync<IJSObjectReference>("import", "./js/Counter.js");
        await module.InvokeVoidAsync("displayAlert", "New message");
    }
}

I get the following error The type or namespace IJSObjectReference could not be found. There is no option to install the package in intellisense too assuming it's a missing package issue. I have searched but haven't seen anything related. I am thinking this issue has something to do with the .NET 5 release or maybe there is a package I need to install.

Questioner
Qudus
Viewed
0
Qudus 2020-12-09 00:02:17

IJSObjectReference is only available with the .NET 5. So, creating the project with .NET 5 fixed the issue.