skip to Main Content

I have created a C# function in Azure using Visual Studio Code and followed the below steps to

  1. Select a language for your function project –> Choose C#.
  2. Select a .NET runtime — > Choose .NET 8.0 Isolated (LTS).
  3. Select a template for your project’s first function –> Choose HTTP trigger.1
  4. Provide a function name Type –> HttpExample.
  5. Provide a namespace Type –> My.Functions.
  6. Authorization level –> Choose Anonymous.
  7. open your project –>Select Open in current window.

after this steps i build and tried to run the app locally,
I got error:

dotnet run
Unhandled exception. System.InvalidOperationException: The gRPC channel URI 'http://:' could not be parsed.
   at Microsoft.Extensions.DependencyInjection.GrpcServiceCollectionExtensions.GetFunctionsHostGrpcUri(IConfiguration configuration) in D:a_work1ssrcDotNetWorker.GrpcGrpcServiceCollectionExtensions.cs:line 97

enter image description here

how to resolve this issue?

I have tried same steps for .NET 6.0 Isolated (LTS). version its working and running perfectly fine.
I have also updated and install relevant required tools and package updates for .net version 8 but still facing the error.

2

Answers


  1. Chosen as BEST ANSWER

    Here below some steps tried to resolve the given issue.. initially I have followed the steps for setup using (https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs-code?tabs=node-v4%2Cpython-v2%2Cisolated-process&pivots=programming-language-csharp )

    then also did some updates for make it run as below : -

    1. I have update the Azure Functions Package version -v1.14.3
    2. also update the Azure Function Core tool latest version - v4 (Core Tools Version:
      4.0.5700) and (Function Runtime Version: 4.33.2.22572)
    3. Used terminal command to execute function locally in vs code as "func host start"

    enter image description here


  2. I see you are trying to run an Azure isolated function using dotnet run command but you need to use func host start or func start command to run an Azure function.

    I have created a default .Net8 isolated function using the template in visual studio code and my function code looks like below-

    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Azure.Functions.Worker;
    using Microsoft.Extensions.Logging;
    
    namespace Company.Function
    {
        public class HttpTrigger1
        {
            private readonly ILogger<HttpTrigger1> _logger;
    
            public HttpTrigger1(ILogger<HttpTrigger1> logger)
            {
                _logger = logger;
            }
    
            [Function("HttpTrigger1")]
            public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
            {
                _logger.LogInformation("C# HTTP trigger function processed a request.");
                return new OkObjectResult("Welcome to Azure Functions!");
            }
        }
    }
    

    In order to run the function either navigate to Run -> Start Debugging or Run without Debugging in visual studio code. You can also execute your function using func host start or func start command in terminal as shown below-

    C:Users********DocumentsfunctionApp78437173> func host start
    MSBuild version 17.9.8+b34f75857 for .NET
      Determining projects to restore...
      All projects are up-to-date for restore.
      78437173 -> C:Users*******DocumentsfunctionApp78437173binoutput78437173.dll
      Determining projects to restore...
      Restored C:Users*******AppDataLocalTempoclw0pui.c1oWorkerExtensions.csproj (in 456 ms).
      WorkerExtensions -> C:Users******AppDataLocalTempoclw0pui.c1obuildoutMicrosoft.Azure.Functions.Worker.Extensions.dll
    
    Build succeeded.
        0 Warning(s)
        0 Error(s)
    
    Time Elapsed 00:00:03.00
    
    
    
    Azure Functions Core Tools
    Core Tools Version:       4.0.5530 Commit hash: N/A +c8883e7f3c06e2b424fbac033806c19d8d91418c (64-bit)
    Function Runtime Version: 4.28.5.21962
    
    [2024-05-06T15:19:21.268Z] Found C:Users********DocumentsfunctionApp7843717378437173.csproj. Using for user secrets file configuration.
    [2024-05-06T15:19:23.031Z] Worker process started and initialized.
    
    Functions:
    
            HttpTrigger1: [GET,POST] http://localhost:7071/api/HttpTrigger1
    
    For detailed output, run func with --verbose flag.
    [2024-05-06T15:19:27.972Z] Host lock lease acquired by instance ID '000000000000000000000000BF6D1ED5'.
    [2024-05-06T15:19:36.617Z] Executing 'Functions.HttpTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=8a2b699d-77c1-4d02-8cbf-065df810e03f)
    [2024-05-06T15:19:36.960Z] C# HTTP trigger function processed a request.
    [2024-05-06T15:19:36.976Z] Executing OkObjectResult, writing value of type 'System.String'.
    [2024-05-06T15:19:37.097Z] Executed 'Functions.HttpTrigger1' (Succeeded, Id=8a2b699d-77c1-4d02-8cbf-065df810e03f, Duration=476ms)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search