# Grpc.Core.RpcException: Status(StatusCode="Unimplemented", Detail="方法 'ServiceName/MethodName' 未实现。如果服务器未配置为提供此方法，调用将失败。")

- **ID:** `dotnet/grpc-unimplemented-method`
- **领域:** dotnet
- **类别:** protocol_error
- **错误码:** `12`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

gRPC 客户端调用了服务器未注册处理程序的方法，通常是由于缺少服务注册、proto 文件编译错误或客户端与服务器版本不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.45.0 | active | — | — |
| 2.46.0 | active | — | — |
| 2.47.0 | active | — | — |
| 2.48.0 | active | — | — |

## 解决方案

1. ```
   Ensure the service is registered in the DI container and endpoint mapping: in Program.cs, add 'app.MapGrpcService<MyServiceImpl>();' and in the service class, inherit from 'MyService.MyServiceBase' and override the method.
   ```
2. ```
   Regenerate gRPC stubs by running 'dotnet build' after updating the .proto file, or use 'dotnet grpc-aspnetcore-codegen' to ensure both client and server use the same proto definition.
   ```

## 无效尝试

- **** — Restarting the server without updating the code does not add the missing method handler; the service must be properly registered in Startup.cs or Program.cs. (90% 失败率)
- **** — Adding a new proto file without regenerating the server stubs leaves the server unaware of the method; the build step must compile the proto to C#. (70% 失败率)
