skip to Main Content

I have previously used in-process function apps without any issue.

I start them with func host start, and then I can invoke any REST endpoints locally using cURL.

To keep up with later dotnet versions, I’ve decided to give the isolated runtime a try.

I’ve setup a very simple project that only exposes a single endpoint, as outlined in the documentation for the http trigger

public class RestEndpoints
{
    private readonly ILogger<RestEndpoints> _logger;

    public RestEndpoints(ILogger<RestEndpoints> logger)
    {
        _logger = logger;
    }

    [Function(nameof(Run))]
    public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestData req,
        FunctionContext executionContext)
    {
        _logger.LogInformation("message logged");

        var response = req.CreateResponse(HttpStatusCode.OK);
        response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
        response.WriteString("Welcome to .NET isolated worker !!");

        return response;
    }
}

In Program.cs I have the baseline setup. From what I’ve read I can’t see anything additional is needed for this scenario:

using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .Build();

host.Run();

I start this application the same way as I did in-process with func host start. It starts alright and lists my endpoint as:

Run: [GET] http://localhost:7071/api/Run

However, when I try to invoke this using cURL, the call just hangs. I can see log output that the runtime was reached, but I cannot get a response from the endpoint:

[2023-08-22T09:48:28.362Z] Executing ‘Functions.Run’ (Reason=’This function was programmatically called via the host APIs.’, Id=98b63dcc-dce5-4b9d-bee8-dee1ea98a653)

In my csproj file I have the following dependencies:

<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />

I am using Azure Function Core Tools 4.46.0.

What am I missing here?

Trying debug mode

As pointed out to me, I tried debug mode as well but I get the same result:

func host start --pause-on-error --dotnet-isolated-debug --enable-json-output

Azure Functions Core Tools
Core Tools Version:       4.0.5274 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.23.0.20886

[2023-08-22T11:34:02.028Z] Found MyProject.csproj. Using for user secrets file configuration.
[2023-08-22T11:34:04.234Z] Azure Functions .NET Worker (PID: 70640) initialized in debug mode. Waiting for debugger to attach...

Functions:

    Run: [GET] http://localhost:7071/api/Run

For detailed output, run func with --verbose flag.
[2023-08-22T11:34:09.120Z] Host lock lease acquired by instance ID '000000000000000000000000C146DC40'.
[2023-08-22T11:34:10.565Z] Worker process started and initialized.
[2023-08-22T11:35:12.462Z] Executing 'Functions.Run' (Reason='This function was programmatically called via the host APIs.', Id=2a8207da-dc97-447e-b9de-60facda8481c)

The last line in the above output is from me using cURL to try and invoke the endpoint, then nothing else happens.

2

Answers


  1. I have reproduced the issue at my environment and after executing the function in debug mode, it worked for me

    Thanks @Fildor for pointing it out, Even I was also getting the same issue, when I directly tried to start the function using func host start command but then I ran the function like below

    enter image description here

    I got the expected result-

    enter image description here

    Try running the function in debug mode after creation.

    Login or Signup to reply.
  2. I would start by updating your .csproj dependencies with the following values:

    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.18.0"/>
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.13.0"/>
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
    

    You could also attempt to change your output type to ASP.NET Core types as per here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search