.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();
        }
相关推荐
来恩10032 小时前
C# 类与对象详解
开发语言·c#
Dr.勿忘5 小时前
C#面试常考随笔8:using关键字有哪些用法?
开发语言·unity·面试·c#·游戏引擎
xcLeigh6 小时前
WPF进阶 | WPF 数据绑定进阶:绑定模式、转换器与验证
c#·wpf
谢大旭6 小时前
ASP.NET Core 中间件
后端·中间件·c#
时光追逐者7 小时前
Visual Studio使用GitHub Copilot提高.NET开发工作效率
c#·github·.net·copilot·ai编程·微软技术·visual studio
唐青枫8 小时前
dotnet LINQ 使用简明教程
c#·.net
谢大旭10 小时前
.Net Web API 访问权限限定
开发语言·c#
幻想趾于现实12 小时前
如何用函数去计算x年x月x日是(C#)
开发语言·c#
我命由我123451 天前
游戏引擎 Unity - Unity 下载与安装
c语言·开发语言·c++·后端·unity·c#·游戏引擎
我命由我123451 天前
游戏引擎 Unity - Unity 启动(下载 Unity Editor、生成 Unity Personal Edition 许可证)
c语言·c++·后端·unity·c#·游戏引擎·ue4