Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.InvalidOperationException: The gRPC channel URI 'http://0' could not be parsed

Using .NET5 Azure function in Visual Studio 2019, I am getting the below exception from Program.cs:

System.InvalidOperationException: The gRPC channel URI 'http://0' could not be parsed

My Program.cs is below:

public static void Main()
{
    var host = new HostBuilder()
            .ConfigureFunctionsWorkerDefaults()
            .ConfigureServices(services =>
            {
                services.AddSingleton<IConfiguration>(data =>
                {
                    var result = new ConfigurationBuilder()
                        .SetBasePath(Directory.GetCurrentDirectory())
                        .AddJsonFile("AppSettings.json", false, true)
                        .AddJsonFile($"AppSettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
                        .AddEnvironmentVariables()
                        .Build();
                    return result;
                });

                services.AddSingleton<IServiceProvider, ServiceProvider>();
            })
            .UseDefaultServiceProvider(options => options.ValidateScopes = false)
            .Build();

    host.Run();
}

The exception is being thrown from host.Run() in Debug mode. Any clue?

like image 585
Yeasin Abedin Avatar asked Sep 04 '25 16:09

Yeasin Abedin


1 Answers

For me it was occurring in Rider. The issue was that I was running the Function App as a .Net Project instead of as Azure Functions host.

Rider Edit Run/Debug Configuration

like image 135
ubienewbie Avatar answered Sep 07 '25 18:09

ubienewbie