You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
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)
The text was updated successfully, but these errors were encountered:
jviau
changed the title
InvalidOperationException when configuring gRPC client
InvalidOperationException when configuring gRPC client (Grpc.Net.ClientFactory)
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 throwInvalidOperationException
fromValidateGrpcClient
.The reason being without using the overload which includes
Action<GrpcClientFactoryOptions>
, the serviceConfigureNamedOptions<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 fromAddInterceptor
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 hardcodingnameof(AddInteceptor)
The text was updated successfully, but these errors were encountered: