Skip to content

Custom Options C#, Error 'FieldOptions' is inaccessible due to its protection level #6510

Closed
@towny-trp

Description

Version: 3.9.1
Language: C#
Linux & Windows
Protoc: Grpc.Protobuf.Tools.3.9.1

What did you do?
Steps to reproduce the behavior:

  1. Create a simple custom option proto in TestAnnotations.proto:
extend google.protobuf.FieldOptions {
  string test_field_opt1 = 5640936;
}
  1. Generate the c# code and compile via Grpc.Protobuf.Tools.3.9.1

  2. Code generated in invalid as it generates extension methods in the descriptor that access the FieldOptions, which it can't as FieldOptions is internal so you get the following error trying to compile:

Error	CS0122	'FieldOptions' is inaccessible due to its protection level
  1. Including the descriptor.proto in the build gets round the compilation issue (as it's then in the same assembly) - however if you do that you get another error trying to access the descriptor:
Message: System.TypeInitializationException : The type initializer for 'TestAnnotationsReflection' threw an exception.
---- System.ArgumentException : An item with the same key has already been added. Key: Google.Protobuf.ObjectIntPair`1[System.Type]

Anything else we should know about your project / environment
Using the Grpc.Tools 1.22.0 protoc compiler gets round this particular problem, but then you get hit by this issue 6509

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions