The type or namespace IJSObjectReference could not be found

≯℡__Kan透↙ 提交于 2020-12-15 05:25:14

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/65064483/the-type-or-namespace-ijsobjectreference-could-not-be-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!