grpc / grpc/grpc-dotnet

Create GrpcChannel using Grpc.Net.Client with default StaticResolverFactory, the channel.Target returns null

Open
#2,606 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
4.5k
Forks
836
Avg merge
6d 3h
Merged PRs (30d)
7

Description

### What version of gRPC and what language are you using?
.NET8, c#
Grpc.Net.Client v2.67.0

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

### What runtime / compiler are you using (e.g. .NET Core SDK version `dotnet --info`)
Visual Studio 2022

### What did you do?
If possible, provide a recipe for reproducing the error. Try being specific and include code snippets if helpful.

when create channel with single url, ex:
`var channel = GrpcChannel.ForAddress("http://localhost:5000");
Console.WriteLine($"grpc_address='{channel.Target}'"); // will be localhost:5000`

but create channel with default StaticResolverFactory, the channel.Target returns null.
`var addrList = new List() {
new BalancerAddress("127.0.0.1", 5001),
new BalancerAddress("127.0.0.1", 5002)
};

var services = new ServiceCollection();
services.AddSingleton(new StaticResolverFactory(addr => addrList.ToArray()));

channel = GrpcChannel.ForAddress(
"static:///my-example-host",
new GrpcChannelOptions
{
ServiceProvider = services.BuildServiceProvider()
});
Console.WriteLine($"grpc_address='{channel.Target}'"); // return null`

### What did you expect to see?
channel.Target return the original target used to create the channel.

### What did you see instead?
channel.Target return null.

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

See [TROUBLESHOOTING.md](https://github.com/grpc/grpc-dotnet/blob/master/TROUBLESHOOTING.md) for how to diagnose problems better.

### Anything else we should know about your project / environment?

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue using GrpcChannel.ForAddress with the static:///my-example-host target and a StaticResolverFactory, then inspect how GrpcChannel.Target is populated. Verify the behavior against the expected original target and add or update coverage for the channel.Target result.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.