目录
严重性 代码 说明 项目 文件 行 禁止显示状态 详细说明
错误 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();
}