Skip to content

MethodDescriptor.CustomOptions no longer works in 3.11.0-rc2 (when old generated code is used) #6956

Closed
@JamesNK

Description

I want to get custom options off a MethodDescriptor. Specifically I want to get HttpRule which is from Google.Api.CommonProtos 1.7.0. In Google.Protobuf 3.8.0 I can successfully get this option by doing this:

const int HttpRuleFieldId = 72295728;
var success = methodDescriptor.CustomOptions.TryGetMessage<HttpRule>(HttpRuleFieldId, out httpRule);

With Google.Protobuf 3.9.0 and 3.10.0 CustomOptions.TryGetMessage<T> errors, I believe related to this issue: #6824

When I updated to 3.11.0-rc2 CustomOptions.TryGetMessage<T> no longer errors, but it also doesn't return a value. You should fix that for backwards compatibility.

I see that CustomOptions has been made obsolete. How do I use the new API?

const int HttpRuleFieldId = 72295728;
const uint TagId = 0; // what is this?

var extension = new Extension<Google.Protobuf.Reflection.MethodOptions, HttpRule>(HttpRuleFieldId, FieldCodec.ForMessage<HttpRule>(TagId, HttpRule.Parser));
var httpRule = methodDescriptor.GetOption<HttpRule>(extension); // returns null

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