c# - 命名空间中不存在 Blazor 命名空间互操作

标签 c# namespaces interop assembly-references blazor

在哪里可以找到程序集引用以及如何添加它?
错误描述:

CS0234 The type or namespace name 'Interop' does not exist in the namespace 'Microsoft.AspNetCore.Blazor.Browser' (are you missing an assembly reference?)

CS0103 The name 'RegisteredFunction' does not exist in the current context Phoneword.Client


我有一个小的 Blazor 项目,我想在一段时间后再次运行。但似乎我已经删除了引用或其他东西坏了。
编辑我:
开拓者:0.5.1
目标框架:.NET Standard 2.0

最佳答案

'RegisteredFunction' 不再存在。
这是在 JavaScript 文件中定义函数的方式:

window.exampleJsFunctions = {
  showPrompt: function (message) {
    return prompt(message, 'Type anything here');
  }
};
这就是您从 Blazor 代码调用该函数的方式:
using Microsoft.JSInterop;

    public class ExampleJsInterop
    {
        public static Task<string> Prompt(string message)
        {
            // Implemented in exampleJsInterop.js
            return JSRuntime.InvokeAsync<string>(
                "exampleJsFunctions.showPrompt",
                message);
        }
    }

关于c# - 命名空间中不存在 Blazor 命名空间互操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52504547/

相关文章:

C# 用户控件需要在最终应用程序中访问外部 cs 文件

c# - 将 using 语句放入命名空间失败

c# - 将结构数组从 C++ 编码到 C#?

multithreading - COM 互操作中的应用程序域

Java 和 .NET 应用程序互操作性

c# - 以编程方式启用/禁用设备的 Win32 API 函数

c# - 在 c# 中没有多条件情况下将项目添加到 ListView

c# - Linq 计数,问题

c# - Nuget 包未找到和/或使用 System.Security.Cryptography

namespaces - 如何在新旧命名空间中使用 avro 数据