Search code examples
c#grpc.net-6.0.net-7.0

Using gRPC proto from referenced project throws InvalidOperationException


I would like to store and build my protos in an external project that can be used in both client and server projects with JsonTranscoding. Unfortunately, gRPC throws an InvalidOperationException:

'The stored extension value has a type of 'Google.Api.HttpRule, BookingService.RpcApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. This a different from the requested type of 'Google.Api.HttpRule, Google.Api.CommonProtos, Version=2.5.0.0, Culture=neutral, PublicKeyToken=3ec5ea7f18953e47'.'"

I have found a similar problem and it seems fixed. I also use the latest NuGet packages but I get this annoying exception.

Everything is fine if I copy all proto files for the relevant projects but it would be better to use the generated classes from an external reusable dll. Could anyone tell me how can I fix it?


Solution

  • I have fixed it. My case the root cause of the problem was that I set annotations.proto and http.proto to be built. Changed their build action to none solved the exception.

    Edited to add complete solution:

    Do not compile google protos (csproj snippet):

    <Protobuf Include="google\api\annotations.proto" ProtoCompile="false" GrpcServices="None" />
    <Protobuf Include="google\api\http.proto" ProtoCompile="false" GrpcServices="None" />
    

    And use Google.Api.CommonProtos package.