dotnet protocol_error ai_generated true

Grpc.Core.RpcException: Status(StatusCode="Unimplemented", Detail="方法 'YourMethod' 未实现。")

Grpc.Core.RpcException: Status(StatusCode="Unimplemented", Detail="Method 'YourMethod' is unimplemented.")

ID: dotnet/grpc-unimplemented-service

其他格式: JSON · Markdown 中文 · English
90%修复率
88%置信度
1证据数
2023-08-10首次发现

版本兼容性

版本状态引入弃用备注
Grpc.AspNetCore 2.57.0 active
Google.Protobuf 3.24.0 active
Grpc.Tools 2.57.0 active

根因分析

gRPC 客户端调用了服务器未注册或未实现的方法,通常是由于缺少服务绑定或 proto 编译错误。

English

The gRPC client calls a method that the server has not registered or implemented, often due to missing service binding or incorrect proto compilation.

generic

官方文档

https://learn.microsoft.com/en-us/aspnet/core/grpc/troubleshoot?view=aspnetcore-8.0#unimplemented-method

解决方案

  1. 使用 'dotnet grpc' 或 'protoc' 工具从同一 .proto 文件重新生成客户端和服务器存根。确保服务器启动代码映射服务:'app.UseEndpoints(endpoints => { endpoints.MapGrpcService<MyServiceImpl>(); });'
  2. 验证服务已在 DI 容器中注册:'services.AddGrpc();' 和 'services.AddScoped<MyServiceImpl>();',然后在端点中映射。

无效尝试

常见但无效的做法:

  1. 70% 失败

    Checking only the client-side proto file while the server uses an older version causes mismatch; both must be regenerated from the same .proto.

  2. 85% 失败

    Restarting the server without recompiling the service code does not register new methods; the error persists.

  3. 60% 失败

    Assuming the method name is case-insensitive in gRPC leads to wrong endpoint calls; gRPC method names are case-sensitive.