Search code examples
c#blazorblazor-client-side

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.


Solution

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