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

- **ID:** `dotnet/grpc-unsupported-protocol`
- **领域:** dotnet
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

gRPC 客户端调用了服务器没有处理程序的方法，通常是由于服务定义不匹配、缺少方法实现或 proto 文件编译错误导致的。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC C# 2.46.0 | active | — | — |
| Grpc.AspNetCore 2.57.0 | active | — | — |
| Google.Protobuf 3.24.0 | active | — | — |
| .NET 6.0 | active | — | — |
| .NET 7.0 | active | — | — |
| .NET 8.0 | active | — | — |

## 解决方案

1. ```
   Regenerate both client and server stubs from the same .proto file. Example command: protoc --csharp_out=./Client --grpc_out=./Client --plugin=protoc-gen-grpc=grpc_csharp_plugin service.proto
   ```
2. ```
   Verify the server implements all methods defined in the proto file by checking the generated service base class. Ensure no method is missing or commented out.
   ```
3. ```
   Ensure the client is using the correct service address and port. Test with grpcurl: grpcurl -plaintext localhost:50051 list
   ```

## 无效尝试

- **Restarting the server without updating the proto files or regenerating the client stub.** — The issue is a mismatch between client and server definitions; restarting alone does not synchronize them. (95% 失败率)
- **Adding a catch-all method in the server that returns an empty response.** — gRPC relies on strict method contracts; a catch-all violates the protocol and may cause other errors. (90% 失败率)
- **Changing the client to use a different HTTP version (e.g., HTTP/1.1).** — gRPC requires HTTP/2; HTTP/1.1 is not supported and will cause a different error. (100% 失败率)
