Service reflection is failing if proto file imports another proto from different project.
See original GitHub issueWhat version of gRPC and what language are you using?
Here are the dependencies I use:
<PackageReference Include="Google.Protobuf" Version="3.21.3" />
<PackageReference Include="Grpc.Core.Api" Version="2.*" />
<PackageReference Include="Grpc.Tools" Version="2.*">
What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info
)
.NET SDK:
Version: 7.0.100
Commit: e12b7af219
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.100\
Host:
Version: 7.0.0
Architecture: x64
Commit: d099f075e4
.NET SDKs installed:
5.0.414 [C:\Program Files\dotnet\sdk]
7.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
What did you do?
I use GRPCurl service discovery, and I get the following error:
Failed to resolve symbol "radio_data.RadioDataService": Symbol not found: radio_data.RadioDataService
caused by: File not found: CalculationEngine.Shared.Grpc/Protos/data.proto
The reason is that my radio_data
file imports another proto:
import "CalculationEngine.Shared.Grpc/Protos/data.proto";
And csproj file entry is the following:
<ItemGroup>
<Protobuf Include="..\$(MSBuildProjectName)\Protos\radio_data.proto" ProtoRoot=".." GrpcServices="Server,Client" />
</ItemGroup>
Here’s generated DataReflection class for data.proto
:
public static partial class DataReflection {
#region Descriptor
/// <summary>File descriptor for Protos/data.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static DataReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"ChFQcm90b3MvZGF0YS5wcm90bxIEZGF0YSIcCglCeXRlQ2h1bmsSDwoHQ29u",
"dGVudBgBIAEoDCIwCgREYXRlEgwKBFllYXIYASABKAUSDQoFTW9udGgYAiAB",
"KAUSCwoDRGF5GAMgASgFQiCqAh1DYWxjdWxhdGlvbkVuZ2luZS5TaGFyZWQu",
"R3JwY2IGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::CalculationEngine.Shared.Grpc.ByteChunk), global::CalculationEngine.Shared.Grpc.ByteChunk.Parser, new[]{ "Content" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::CalculationEngine.Shared.Grpc.Date), global::CalculationEngine.Shared.Grpc.Date.Parser, new[]{ "Year", "Month", "Day" }, null, null, null, null)
}));
}
#endregion
}
Issue Analytics
- State:
- Created 10 months ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
protocol buffers - Importing Protofile from a different path
proto should reflect the specific package and service or method or message name that you're importing not its disk location (which is what...
Read more >Language Guide (proto 2) | Protocol Buffers Documentation
This guide describes how to use the protocol buffer language to structure your protocol buffer data, including .proto file syntax and how to...
Read more >Troubleshoot gRPC on .NET
gRPC code generation of concrete clients and service base classes requires protobuf files and tooling to be referenced from a project.
Read more >Working with service definitions
If enabled by the server, server reflection can be the easiest way to add the service ... Go to the Service definition tab...
Read more >Tutorial - buf build
The operations on buf are based on Protobuf files that are built or compiled. The linter, breaking change detector, generator, and BSR features...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem is your proto files have different root paths.
models.proto has a compiled path of
Protos/models.proto
, but greet.proto is referencing it asGrpcModels/Protos/models.proto
. These don’t line up, so reflection breaks.It works if the Protobuf line is changed in the model project to this:
@JamesNK the solution you provided is a good one, but I have one case where the GrpcModels project is in a different folder, and reflection does not work in this case, can you suggest any solution for the case when projects are in other folders:
/Models/GrpcModels.csproj FailingGRPCurl.csproj
In this case, I should do an import like this: import “Models/GrpcModels/Protos/model.proto”;
Of course, it would be easy to move projects to the same folder 😃, but logically I need some separation. And if possible, how to adapt to support different folders, that would be very helpful!
Thank you 😃