Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
towny-trp opened this issue Aug 14, 2019 · 3 comments

Comments

@towny-trp
Copy link

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.

@nycdotnet
Copy link

Looking forward to getting the 3.11 version of this (4.0?) Since we're stuck on 3.8 because of this exception.

@jtattermusch
Copy link
Contributor

The patched nuget is now available: https://www.nuget.org/packages/Google.Protobuf/3.10.1
Can you please test and report back if it solves the issue.

@nycdotnet
Copy link

I know this is very old, but I can confirm that Google.Protobuf 3.11.3, Grpc 2.27 + Healthcheck + Reflection play nicely together. Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants