.net core6中程序不包含适合于入口点的静态 “Main“ 方法

目录

严重性 代码 说明 项目 文件 行 禁止显示状态 详细说明

错误 CS5001 程序不包含适合于入口点的静态 "Main" 方法 GrpcGreeterClient F:\Users\invengo\source\repos\GrpcGreeterClient\CSC 1 活动 程序不包含适合于入口点的静态 "Main" 方法

报错代码

csharp 复制代码
        static async void Main(string[] args)
        {
            // The port number must match the port of the gRPC server.
            using var channel = GrpcChannel.ForAddress("https://localhost:7232");
            var client = new Greeter.GreeterClient(channel);
            var reply = await client.SayHelloAsync(
                              new HelloRequest { Name = "GreeterClient" });
            Console.WriteLine("Greeting: " + reply.Message);
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }

问题描述

在Main方法中使用await调用异步方法,报错

处理方案

修改为: static async Task Main(string[] args)

编译通过,问题解决。

修改后的代码

csharp 复制代码
        static async Task Main(string[] args)
        {
            // The port number must match the port of the gRPC server.
            using var channel = GrpcChannel.ForAddress("https://localhost:7232");
            var client = new Greeter.GreeterClient(channel);
            var reply = await client.SayHelloAsync(
                              new HelloRequest { Name = "GreeterClient" });
            Console.WriteLine("Greeting: " + reply.Message);
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
相关推荐
心念枕惊3 小时前
OpenClaw.NET 重大更新:Goal 机制登场,让 AI Agent 不再“半途而废“
.net
颜x小6 小时前
[C#]泛型类与泛型方法
开发语言·c++·c#
caishenzhibiao6 小时前
顺势交易矩阵主图 同花顺期货通指标
java·c语言·c#
TDengine (老段)7 小时前
TDengine Node.js 与 C# 连接器 — Web 服务与 .NET 集成
大数据·数据库·node.js·c#·.net·时序数据库·tdengine
河西石头8 小时前
再谈C#的抽象类和接口:从“适配器”到“毛坯房”的设计哲学
开发语言·c#·接口·依赖注入·抽象类·依赖倒挂
颜x小8 小时前
[C#]——接口与继承
开发语言·c++·c#
颜x小1 天前
[C#] C++与c#语法对比
开发语言·c++·c#
weixin_423652131 天前
C#使用JObject
开发语言·c#
Z5998178411 天前
c#软件开发学习笔记--Modbus-RTU通讯
笔记·学习·c#