grpc: Grpc.Tools 2.30 does not generate correct client code.

Doing my first grpc greeter sample (template) and following the tutorial to create a C# client. https://docs.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-3.0&tabs=visual-studio

The following code does not compile with Grpc.Tools v2.30 (Greeter.GreeterClient does not exist)

var client =  new Greeter.GreeterClient(channel);

Grpc.Tools v2.29 works fine.

HIH/2c

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

Today I was setting up my first grpc greeter sample, too. I faced the exactly same problem like you when using the tutorial https://docs.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-3.0&tabs=visual-studio.

In step “Add greet.proto” I added the following to my project file:

<ItemGroup>
  <Protobuf Include="Protos\greet.proto" GrpcServices="Client" />
</ItemGroup>

As it just added a folder with a dead link to my project, I deleted the link and added the file “greet.proto” myself. This led to default file properties what leaded to missing generating of client code. Then I corrected the properties as shown in the attachment, client code gets generated as expected.

Hope this helps. greet_proto_fileproperties

Looks like the problem was due to incorrectly setting "GrpcServices="Server" in <Protobuf ... />?

https://github.com/obiwanjacobi/Grpc23713/blob/afa629e6b36ac65532a844b3e8c40b31de75c942/GrpcService1/GrpcService1.csproj#L8

When that option is on, it won’t generate the client code, which seems to match what you’re seeing.

I tried the following:

  1. Added a copy of greet.proto to the server. Named it greet2 and changed the package, namespace and service name with a 2-postfix.
  2. Dragged and dropped the new .proto file into my client (console) project. That generated an entry in the .csproj file with GrpcServices="Server" - changed that to Client and saved the .csproj.
  3. Tagged on the 2-postfix to the code in Program.cs to use the new proto definition.
  4. Build dotnet build Grpc23713.sln fails. The client class was not generated.

So somehow it seems to be linked to the way I add a new proto file to the client project?

Deleting the obj folder and rebuilding fixes the issue (regenerating). Hope this helps.