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

C#: MethodDescriptor.GetOption throws NullReferenceException #7127

Closed
JamesNK opened this issue Jan 23, 2020 · 2 comments
Closed

C#: MethodDescriptor.GetOption throws NullReferenceException #7127

JamesNK opened this issue Jan 23, 2020 · 2 comments

Comments

@JamesNK
Copy link
Contributor

JamesNK commented Jan 23, 2020

MethodDescriptor.GetOption<T>(Extension<MethodOptions, T> extension) throws NullReferenceException when the method descriptor does not have the option on it. I would expect it to return null.

My code:

private bool TryGetHttpRule(MethodDescriptor methodDescriptor, out HttpRule httpRule)
{
    var extension = AnnotationsExtensions.Http;
    httpRule = methodDescriptor.GetOption(extension);

    return httpRule != null;
}

Google.Protobuf 3.11.2
Google.Api.CommonProtos 2.0.0-beta01

@JamesNK
Copy link
Contributor Author

JamesNK commented Jan 23, 2020

Proto:

syntax = "proto3";

import "google/api/annotations.proto";
import "google/protobuf/wrappers.proto";
import "google/protobuf/empty.proto";

package http_api;

service HttpApiGreeter {
  rpc NoOption (HelloRequest) returns (HelloReply);
  rpc SayHello (HelloRequest) returns (HelloReply) {
    option (google.api.http) = {
      get: "/v1/greeter/{name}"
    };
  }
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

MethodDescriptor that throws is NoOption

@JamesNK JamesNK changed the title MethodDescriptor.GetOption throws NullReferenceException C#: MethodDescriptor.GetOption throws NullReferenceException Jan 23, 2020
@jtattermusch
Copy link
Contributor

This is fixed by introducing a new GetOptions() API and deprecating the "GetOption" API #7434.

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.

2 participants