grpc / grpc

The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)

Home Page:https://grpc.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Grpc.Tools: AdditionalProtocArguments base_namespace error

jchannon opened this issue · comments

What version of gRPC and what language are you using?

    <PackageReference Include="Google.Protobuf" Version="3.21.0" />

    <PackageReference Include="Grpc.Net.Client" Version="2.46.0" />

    <PackageReference Include="Grpc.Tools" Version="2.46.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>

What operating system (Linux, Windows,...) and version?

macOS 12.4

What runtime / compiler are you using (e.g. python version or version of gcc)

.NET 6 / SDK 6.0.300

What did you do?

In my csproj I specified this:

<Protobuf Include="Protos\greet.proto" GrpcServices="Client" AdditionalProtocArguments="--csharp_opt=base_namespace=Example" />

My proto file is:

syntax = "proto3";

package greet;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply);
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings.
message HelloReply {
  string message = 1;
  oneof test_oneof{
    string name = 2;
    int32 age = 3;
  }
}

When I build my project I get the error Protos/greet.proto: Namespace Greet is not a prefix namespace of base namespace Example

What did you expect to see?

My generated files created with a namespace of Example

What did you see instead?

The error mentioned above`

Anything else we should know about your project / environment?

commented

When you use the --csharp_opt=base_namespace=Example option the base namespace given must match the prefix in the namespace given in the proto file.

In the example above you need to change the proto file to contain:

package Example.greet;

it will generate C# code with:

namespace Example.Greet {

See https://developers.google.com/protocol-buffers/docs/reference/csharp-generated