.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();
        }
相关推荐
xiaoshuaishuai81 小时前
C# 实现Workstation相关功能
开发语言·windows·c#
游乐码1 小时前
c#Lsit排序
开发语言·c#
hard_coding_wang1 小时前
了解一个Excel批量替换的公式用法:REDUCE + LAMBDA 实现循环替换
开发语言·c#·excel
傻啦嘿哟2 小时前
Python 操作 Word 页眉页脚完整指南
开发语言·c#
chao1898442 小时前
C# 读取和绘制 Shapefile (SHP) 文件
c#
大G的笔记本2 小时前
Java WebSocket客户端--java.net.http.HttpClient
java·websocket·.net
波波0072 小时前
每日一题:.NET 性能优化常用手段有哪些?
性能优化·.net
时光追逐者2 小时前
C#/.NET/.NET Core技术前沿周刊 | 第 69 期(2026年4.01-4.12)
c#·.net·.netcore
CSharp精选营2 小时前
for和foreach到底谁快?刚子跑了1亿次循环,告诉你真相
c#·.net·foreach·for循环