user3125693
user3125693

Reputation: 950

Protobuf import failure

Does anyone know where I can find an example of a gRPC protobuf file that imports from a different file and uses a protobuf message in a return? I can't find any at all.

I have a file...

syntax = "proto3";
package a1;
import "a.proto";
service mainservice {
  rpc DoSomething(...) returns (a.SomeResponse) {}


}

a.proto is also in the same directory and also compiles by itself. The error messages I'm getting are: "a.SomeResponse" is not defined. mainfile.proto: warning: Import a.proto but not used.

Upvotes: 21

Views: 10665

Answers (2)

user3125693
user3125693

Reputation: 950

Found the answer... need to make sure the package name of a.proto is used when specifying the object imported (eg: a_package_name.SomeResponse). Example:

base.proto

syntax = "proto3";
option csharp_namespace = "Api.Protos";
package base;
message BaseResponse {
    bool IsSuccess = 1;
    string Message = 2;
}

user.proto

syntax = "proto3";
import "Protos/base.proto";
option csharp_namespace = "Api.Protos";
package user;

message UserCreateResponse {
    base.BaseResponse response = 1;
}

Upvotes: 46

Shawn Tang
Shawn Tang

Reputation: 1

Seems import from root but not current proto file's folder. So you need add 'Proto/a.proto' if all your proto files are under Proto folder.

Upvotes: 0

Related Questions