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

InvalidOperationException when configuring gRPC client (Grpc.Net.ClientFactory) #2158

Closed
jviau opened this issue Jun 12, 2023 · 0 comments · Fixed by #2159
Closed

InvalidOperationException when configuring gRPC client (Grpc.Net.ClientFactory) #2158

jviau opened this issue Jun 12, 2023 · 0 comments · Fixed by #2159
Labels
bug Something isn't working

Comments

@jviau
Copy link

jviau commented Jun 12, 2023

What version of gRPC and what language are you using?

C# / .NET: Grpc.Net.ClientFactory/2.53.0

What operating system (Linux, Windows,...) and version?

Applicable to all OS/versions

What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info)

dotnet 7

What did you do?

If possible, provide a recipe for reproducing the error. Try being specific and include code snippets if helpful.

It appears any extension method from GrpcHttpClientBuilderExtensions do not work when using .AddGrpcClient<T>() (and NOT .AddGrpcClient<T>(Action<GrpcClientFactoryOptions>)). These methods will always throw InvalidOperationException from ValidateGrpcClient.

The reason being without using the overload which includes Action<GrpcClientFactoryOptions>, the service ConfigureNamedOptions<GrpcClientFactoryOptions> is never added, and so the validation check will always fail.

The fix should be as simple as changing .AddGrpcClient<T>() to call the action-accepting overload. IE: .AddGrpcClient(_ => { }).

What did you expect to see?

Able to use .AddGrpcClient<T>().AddInterceptor(...)

What did you see instead?

InvalidOperationException thrown from AddInterceptor call.

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

See TROUBLESHOOTING.md for how to diagnose problems better.

Anything else we should know about your project / environment?

This is easily worked around for end users by using the other overload. However, my situation is I am adding an SDK extension to the Azure Functions isolated dotnet worker, and so this workaround needs to be passed on to our customers, which is not ideal.

Side note

Also consider updating ValidateGrpcClient to use [CallerMemberName] string? caller = null instead of hardcoding nameof(AddInteceptor)

@jviau jviau added the bug Something isn't working label Jun 12, 2023
@jviau jviau changed the title InvalidOperationException when configuring gRPC client InvalidOperationException when configuring gRPC client (Grpc.Net.ClientFactory) Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant