I have a .NET 8 Azure timer function running in isolation mode and trying to debug it locally on my Mac, but keep getting errors when running it. I also have a http trigger function in the same project and it works. I'm seeing both failed to acquire host lock lease errors and The listener for function 'Functions.SendNotificationTimer' was unable to start errors.
[2024-03-10T20:42:50.803Z] The listener for function 'Functions.SendNotificationTimer' was unable to start.
[2024-03-10T20:42:50.803Z] The listener for function 'Functions.SendNotificationTimer' was unable to start. Azure.Core: Retry failed after 6 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (Connection refused (127.0.0.1:10000)) (Connection refused (127.0.0.1:10000)) (Connection refused (127.0.0.1:10000)) (Connection refused (127.0.0.1:10000)) (Connection refused (127.0.0.1:10000)) (Connection refused (127.0.0.1:10000)). Azure.Core: Connection refused (127.0.0.1:10000). System.Net.Http: Connection refused (127.0.0.1:10000). System.Net.Sockets: Connection refused.
[2024-03-10T20:43:09.115Z] Host instance '0000000000000000000000008F76DCB3' failed to acquire host lock lease: Azure.Core: Connection refused (127.0.0.1:10000). System.Net.Http: Connection refused (127.0.0.1:10000). System.Net.Sockets: Connection refused.
[2024-03-10T20:43:37.473Z] Host instance '0000000000000000000000008F76DCB3' failed to acquire host lock lease: Azure.Core: Connection refused (127.0.0.1:10000). System.Net.Http: Connection refused (127.0.0.1:10000). System.Net.Sockets: Connection refused.
[2024-03-10T20:44:03.701Z] Host instance '0000000000000000000000008F76DCB3' failed to acquire host lock lease: Azure.Core: Connection refused (127.0.0.1:10000). System.Net.Http: Connection refused (127.0.0.1:10000). System.Net.Sockets: Connection refused.
[2024-03-10T20:44:30.433Z] Host instance '0000000000000000000000008F76DCB3' failed to acquire host lock lease: Azure.Core: Connection refused (127.0.0.1:10000). System.Net.Http: Connection refused (127.0.0.1:10000). System.Net.Sockets: Connection refused.
[2024-03-10T20:44:47.967Z] Retrying to start listener for function 'Functions.SendNotificationTimer' (Attempt 8)
Here is the code, but I don't think this is the problem as I also have an http trigger function in this solution as well and it works.
I saw this post, The listener for function 'Function1' was unable to start when running a timer function, but it was running fine locally.
This post, The listener for function 'Functions.trigger' was unable to start? while running Azure function locally, but I'm using Azurite on a Mac. A connection error does flash up at some point, as one of the answers mentions.
I've followed Code and test Azure Functions locally and Use the Azurite emulator for local Azure Storage development for Azurite and Quickstart: Create a C# function in Azure using Visual Studio Code.
SendNotificationTimer.cs
using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace MyCompany.Notifications
{
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();
notificationFunction.csproj
<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>
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}
host.json
{
"version": "2.0",
"logging": {
"logLevel": {
"default": "Debug"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
}

This error occurs if there is already an instance of that particular host is running, or if the host process is not shutting down properly.
local.settings.json:I have created a Function project with both Http trigger and Timer Trigger and working as expected.
Program.cs:
Function.cs:
Console Output: