lcj
lcj

Reputation: 1787

0 functions found in terminal when creating a .NET 8 isolated Azure Function using VS Code on a Mac

I created a new C# timer function in VS Code using .Net 8 in isolated mode and am getting 0 functions found in the terminal on my Mac.

[2024-03-10T14:43:25.386Z] Reading functions metadata
[2024-03-10T14:43:25.386Z] 0 functions found
[2024-03-10T14:43:25.393Z] 0 functions loaded

I don't see the functions listed here like in some of the demos:

enter image description here

When I do run the debugger this message pops up for a second:

enter image description here

but returns to this:

enter image description here

I read this post (though I'm not migrating) on No job functions found, migrating to .net 8 isolated worker process, but I have "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated" in local.settings.json.

I read this post on Functions on .net5: No job functions found. Try making your job classes and methods public, but my .csproj already has <OutputType>Exe</OutputType> in it.

I read this post on 0 functions loaded for isolated but the attributes on my functions are already using the attribute Function.

There was no answer that I could see to this one A warning "No job functions found..." occurs in Terminal logs when debugging a C# project, but the problem looks similar to mine.

The timer function:

public class SendNotificationTimer
{
    private readonly ILogger _logger;

    public SendNotificationTimer(ILoggerFactory loggerFactory)
    {
        _logger = loggerFactory.CreateLogger<SendNotificationTimer>();
    }

    [Function("SendNotificationTimer")]
    public void Run([TimerTrigger("*/30 * * * * *")] TimerInfo myTimer)
    {
        _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        
        if (myTimer.ScheduleStatus is not null)
        {
            _logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}");
        }
    }
}

program.cs:

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services => {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

host.Run();

host.json

{
    "version": "2.0",
    "logging": {
      "logLevel": {
        "default": "Debug"
      },
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
              "excludedTypes": "Request"
            },
            "enableLiveMetricsFilters": true
        }
    }
}

local.settings.json is:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}

.csproj is:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <RootNamespace>_78127464</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

I have these relevant extensions in VS Code:

Upvotes: 1

Views: 836

Answers (1)

lcj
lcj

Reputation: 1787

I followed these instructions and got it working:

brew tap azure/functions
brew install azure-functions-core-tools@4
# if upgrading on a machine that has 2.x or 3.x installed:
brew link --overwrite azure-functions-core-tools@4

Upvotes: 1

Related Questions