I’m not a Windows/Visual Studio person, so maybe I’m doing something obviously wrong. I’m going to have to write a gRPC wrapper around a library for .NET 4.8. That means I won’t be able to use the newer grpc-dotnet and should use the older Grpc.Core
library.
As far as I can tell, I need to manually generate the C# code using protoc, so I’m using this command:
protoc --proto_path=. --csharp_out=grpc .greet.proto --grpc_out=grpc --plugin=protoc-gen-grpc="C:usersfoo.nugetpackagesgrpc.tools.5.0toolsgrpc_csharp_plugin.exe"
I get two files Greet.cs
and GreetGrpc.cs
which I add to my Visual Studio project. I’ve also added some nuggets I thought are relevant (Google.Protobuf
, Grpc.Core
, Grpc.Tools
, Grpc.Net.Client
). The generated code does not compile though.
For example this line:
static readonly Marshaller<global::Greet.HelloRequest> __Marshaller_HelloRequest = Marshallers.Create((arg) => arg.ToByteArray(), global::Greet.HelloRequest.ParseFrom);
would cause an error:
‘HelloRequest’ does not contain a definition for ‘ParseFrom’
Also this line:
static readonly Method<global::Greet.PrepareRequest, global::Greet.PrepareResponse> __Method_Prepare = new Method<global::Greet.PrepareRequest, global::Greet.PrepareResponse>(
MethodType.Unary,
"Prepare",
__Marshaller_PrepareRequest,
__Marshaller_PrepareResponse);
causes:
There is no argument given that corresponds to the required parameter ‘responseMarshaller’ of ‘Method<PrepareRequest, PrepareResponse>.Method(MethodType, string, string, Marshaller, Marshaller)’
I would appreciate any help.
8
Your protoc
command appears to be using an ancient version of the csharp grpc plugin that was released way back in 2015! I would guarantee that the generated C# has come a long way since then.
--plugin=protoc-gen-grpc="C:usersfoo.nugetpackagesgrpc.tools.5.0toolsgrpc_csharp_plugin.exe"
You’ve stated in the comments that the project/solution is using the latest version (currently 2.68.1). You should update the --plugin=protoc-gen-grpc=
option to refer to the installed version so that the generated C# code is in-sync with the installed GRPC.Core package.
C:usersfoo.nugetpackagesgrpc.tools2.68.1
directory.