0

I create a new project with an Azure Function in .NET 8. In my local.settings.json file, I create a time trigger like this:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
        "TimerTrigger": "0 59 23 * * * *",
    }
}

My Azure Function uses the TimerTrigger value:

public async Task Run([TimerTrigger("%TimerTrigger%", RunOnStartup = true)] TimerInfo myTimer) 
{ ... }

And my Program.cs looks like this:

var builder = new HostBuilder();
builder.ConfigureFunctionsWebApplication();
builder.Build().Run();

I tried to run it in debug mode, but I always get this error:

Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.Test'. Microsoft.Azure.WebJobs.Host: '%TimerTrigger%' does not resolve to a value.

What I found is that my local.settings.json is different in my bin/debug folder and looks like this:

{
   "IsEncrypted": true,
   "Values": {
       "FUNCTIONS_WORKER_RUNTIME": "################################"
   }
}

My file is set to be copied if newer, but, also with copy always, it lost my configuration.

But, when I start the application, settings are copied well. The problems seems related to this prompt on startup:

enter image description here

I choose isolated worker model. Is this my error? Where is the problem?

My csproj:

<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
      <TargetFramework>net8.0</TargetFramework>
      <AzureFunctionsVersion>v4</AzureFunctionsVersion>
      <OutputType>Exe</OutputType>
      <ImplicitUsings>enable</ImplicitUsings>
      <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
      <FrameworkReference Include="Microsoft.AspNetCore.App" />
      <PackageReference Include="Azure.Storage.Blobs" Version="12.24.0" />
      <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.23.0" />
      <!-- Application Insights isn't enabled by default. See https://aka.ms/AAt8mw4. -->
      <!-- <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" /> -->
      <!-- <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" /> -->
      <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.1" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
      <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
      <PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.4" />
  </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>

SOLVED

The problem was in my local.settings.json. It contains some other configurations in JSON format and that cause the issue. I changed this part with single level property. In this way prompt disappear and all works fine.

9
  • Did you create the function using function core tools? Delete bin and obj folders and try running the function again. Commented May 7 at 7:58
  • I created it with Visual Studio 2022, so it created the default Azure Function. I already tried to empty folder but, after the prompt, my settings are lost. Commented May 7 at 8:10
  • Please share your .csproj code. Commented May 7 at 8:12
  • 1
    Are you facing the same issue with a new function as well? Commented May 7 at 9:39
  • 1
    I found the problem. In my host.settings.json there is also another setting (that I omitted) in Values. I wrote this part like a normal json, so "BlobStorageConfig": { "param": "val" }. This causes the issue. Changed to "BlobStorageConfig:Param": "val" and now it works! Commented May 7 at 10:41

2 Answers 2

1

You are getting the prompt to select the worker runtime because the function is not able to load local.settings.json.

I have tried the same by removing local.settings.json and got the same error. Looks the issue is due to misconfiguration.

To resolve this, delete the existing local.settings.json and create the same file again under the root directory of the project.

Or create a completely new Timer Trigger function and add below configuration in local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    "TimerTrigger": "0 59 23 * * *"
  }
}

Right click on local.settings.json=>properties, Copy if newer for the build action Copy to output directory.

.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.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>

Program.cs:

var builder = FunctionsApplication.CreateBuilder(args);
builder.ConfigureFunctionsWebApplication();
builder.Build().Run();

Function.cs:

[Function("Function1")]
public void Run([TimerTrigger("%TimerTrigger%")] 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}");
    }
}

Able to run the function successfully:

[2025-05-07T10:12:20.532Z] Found C:\Users\uname\Source\Repos\FunctionApp\FunctionApp6\FunctionApp.csproj. Using for user secrets file configuration.
[2025-05-07T10:12:24.364Z] Azure Functions .NET Worker (PID: 10960) initialized in debug mode. Waiting for debugger to attach...
[2025-05-07T10:12:24.415Z] Worker process started and initialized.

Functions:

        Function1: timerTrigger

For detailed output, run func with --verbose flag.
[2025-05-07T10:12:29.426Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
Sign up to request clarification or add additional context in comments.

Comments

0

UPDATE:

The problem in your local.settings.json should be the missing configuration for the AzureWebJobsStorage and the NCRONTAB expression. Can you please adjust it to use the local Azurite Storage emulator for local development and only use 6 instead of 7 fields:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
        "TimerTrigger": "0 59 23 * * *",
    }
}

First Version:

My configuration is the same except for the startup of the Function project. You are using the IHostBuilder with the following config: IHostBuilder config

What I would recommend is to use the IHostApplicationBuilder which is the default configuration when you create new projects with Rider. The config can be found here: IHostApplicationBuilder config

Your program should now look like this:

var builder = FunctionsApplication.CreateBuilder(args);

builder.ConfigureFunctionsWebApplication();

builder.Build().Run();

With this configuration everything is working fine on my end.

3 Comments

Same problem also with FunctionsApplication.CreateBuilder. After the promp, I lost my local settings.
Okay, seems very strange to me. The only thing I am realizing is that your NCRON Expression has one "place" to much. Like in the docs here: learn.microsoft.com/en-us/azure/azure-functions/… you only have 6 fields and you are using 7 fields. But that should not resolve your problem I guess.
@erikscandola edited the answer, can you please check the update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.