.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();
        }
相关推荐
wearegogog1235 小时前
C# .NET 文件比较工具 WinForms
开发语言·c#·.net
糖不吃5 小时前
WPF值转换器
c#
学以智用5 小时前
.NET Core Swagger 超详细讲解(从入门到企业级)
后端·.net
Popeye-lxw7 小时前
由罗技 K380 键盘 FN 键模式切换引发的血案
c#
FL16238631297 小时前
C# OpenCvSharp 基于霍夫变换直线检测的文本图像倾斜校正文本图像倾斜校
开发语言·c#
aini_lovee8 小时前
C# 快递单打印系统(万能套打系统)
开发语言·c#
白菜上路8 小时前
C# Serilog.AspNetCore基本使用
c#·serilog
小白不白1119 小时前
C# WinForm 与 VP 二次开发
开发语言·c#
SunnyDays101110 小时前
如何使用 C# 自动调整 Excel 行高和列宽
开发语言·c#·excel
itgather11 小时前
OfficeExcel — Word / Excel DLL 验证台功能介绍
c#·word·excel