Qudus
Qudus

Reputation: 1520

The type or namespace IJSObjectReference could not be found

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.

Upvotes: 3

Views: 1385

Answers (1)

Qudus
Qudus

Reputation: 1520

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

Upvotes: 2

Related Questions