Skip to content

InvalidOperationException when 'UseStringProtoEnumValueNames' enabled  #60

Description

@Havret

Describe the bug

When I try to serialize an object created based on the following proto file

syntax = "proto3";

option csharp_namespace = "System.Text.Json.Protobuf.Tests";

message MessageWithEnum {
  TestEnum enum_field = 1;
  int32 regular_field = 2;
}

enum TestEnum {
  UNKNOWN = 0;
  FIRST_OPTION = 1;
  SECOND_OPTION = 2;
}

I'm getting the following exception:

System.InvalidOperationException
EnumType is only valid for enum fields.
   at Google.Protobuf.Reflection.FieldDescriptor.get_EnumType()
   at Protobuf.System.Text.Json.ProtobufConverter`1.<>c__DisplayClass3_0.<.ctor>b__2(FieldDescriptor fieldDescriptor) in /Users/havret/git/System.Text.Json.Protobuf/src/Protobuf.System.Text.Json/ProtobufConverter.cs:line 32
   at System.Linq.Enumerable.SelectIListIterator`2.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Protobuf.System.Text.Json.ProtobufConverter`1..ctor(JsonSerializerOptions jsonSerializerOptions, JsonProtobufSerializerOptions jsonProtobufSerializerOptions) in /Users/havret/git/System.Text.Json.Protobuf/src/P

Expected behavior

No exception should be thrown.

Environment:

  • OS: macOS Ventura 13.4.1 (22F82)
  • Version: 1.2.0

Additional context

Serialization works fine when there are only enum fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions