Skip to content

Custom Options C#, 'TypeInitializationException' System.IndexOutOfRangeException : Index was outside the bounds of the array #6509

Closed
@towny-trp

Description

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

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.Tools.1.22.0

  2. Try and access the custom options:

var options = TestAnnotationsReflection.Descriptor.CustomOptions;
  1. See error "System.IndexOutOfRangeException : Index was outside the bounds of the array"
at Google.Protobuf.Reflection.ExtensionCollection.<>c__DisplayClass2_0.<.ctor>b__0(FieldDescriptorProto extension, Int32 i) in C:\develop\protobuf-master\csharp\src\Google.Protobuf\Reflection\ExtensionCollection.cs:line 51
   at Google.Protobuf.Reflection.DescriptorUtil.ConvertAndMakeReadOnly[TInput,TOutput](IList`1 input, IndexedConverter`2 converter) in C:\develop\protobuf-master\csharp\src\Google.Protobuf\Reflection\DescriptorUtil.cs:line 59
   at Google.Protobuf.Reflection.ExtensionCollection..ctor(FileDescriptor file, Extension[] extensions) in C:\develop\protobuf-master\csharp\src\Google.Protobuf\Reflection\ExtensionCollection.cs:line 49
   at Google.Protobuf.Reflection.FileDescriptor..ctor(ByteString descriptorData, FileDescriptorProto proto, IEnumerable`1 dependencies, DescriptorPool pool, Boolean allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo) in C:\develop\protobuf-master\csharp\src\Google.Protobuf\Reflection\FileDescriptor.cs:line 87
   at Google.Protobuf.Reflection.FileDescriptor.BuildFrom(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, Boolean allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo) in C:\develop\protobuf-master\csharp\src\Google.Protobuf\Reflection\FileDescriptor.cs:line 340
   at Google.Protobuf.Reflection.FileDescriptor.FromGeneratedCode(Byte[] descriptorData, FileDescriptor[] dependencies, GeneratedClrTypeInfo generatedCodeInfo) in C:\develop\protobuf-master\csharp\src\Google.Protobuf\Reflection\FileDescriptor.cs:line 400
   at TestAnnotationsReflection..cctor()

Anything else we should know about your project / environment
Changing to use the Porotc Compiler to Google.Protobuf.Tools v 3.9.1 resolves this particular, unfortunately I can't use that as a work around as that introduces another error 'FieldOptions' is inaccessible due to its protection level for which I will log a separate bug.

Activity

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions