Resolving "No job functions found" Error in Azure Functions

Muhammad Haseeb Rehman 30 Reputation points
2023-12-25T14:30:05.5166667+00:00

Hello,

I'm encountering an issue with my Azure Functions project that's causing a persistent "No job functions found. Try making your job classes and methods public" error. Despite following the standard guidelines, the error persists. Here are the details:

  • Azure Functions Core Tools Version: 4.0.5455 (64-bit)
  • Function Runtime Version: 4.27.5.21554

The error occurs when running the function app locally and the full message is as follows:

[2023-12-25T14:17:48.218Z] Found /Users/username/Downloads/Programming/ProjectName/ProjectName.csproj. Using for user secrets file configuration.

[2023-12-25T14:17:49.193Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\MealzNow.Core\MealzNow.Core.csproj" />
    <ProjectReference Include="..\MealzNow.Services\MealzNow.Services.csproj" />
    <ProjectReference Include="..\MealzNow.Db\MealzNow.Db.csproj">
      <GlobalPropertiesToRemove></GlobalPropertiesToRemove>
    </ProjectReference>
  </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>
using MealzNow.Services;
using MealzNow.Db;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

using var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddConsole();
});

var logger = loggerFactory.CreateLogger<Program>();

try
{
    var config = new ConfigurationBuilder()
        .AddJsonFile("local.settings.json", optional: true)
        .AddEnvironmentVariables()
        .Build();

    var cosmosDbAccount = config.GetValue<string>("CosmosDb:Account")
    var cosmosDbKey = config.GetValue<string>("CosmosDb:Key")
    var cosmosDbDatabaseName = config.GetValue<string>("CosmosDb:DatabaseName")

    var host = new HostBuilder()
        .ConfigureServices((context, services) =>
        {
            services.AddDbContext<MealzNowDataBaseContext>(options =>
                options.UseCosmos(cosmosDbAccount, cosmosDbKey, cosmosDbDatabaseName));

             services.AddRepositories(config);
             services.AddServices(config);
             services.AddAutoMapper(typeof(Program));

        }).ConfigureFunctionsWorkerDefaults()
        .Build();

    await host.RunAsync();
}
catch (Exception ex)
{
    logger.LogCritical("JW: " + ex.Message);
}
using System.Net;
using System.Text.Json;
using MealzNow.Core.RequestModels;
using MealzNow.Services.Interfaces;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace MealzNow.MobApi
{
    public class MealzNowMobAppApi
    {
        private readonly ILogger _logger;
        private readonly IAppService _appService;

        public MealzNowMobAppApi(ILoggerFactory loggerFactory, IAppService appService)
        {
            _logger = loggerFactory.CreateLogger<MealzNowMobAppApi>();
            _appService = appService;
        }

        [Function(nameof(GetClientFranchises))]
        public async Task<HttpResponseData> GetClientFranchises([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req)
        {
            _logger.LogInformation("Calling GetClientFranchises funtion");

            var content = await new StreamReader(req.Body).ReadToEndAsync();

            if (content == null)
                return req.CreateResponse(HttpStatusCode.BadRequest);

            var request = JsonConvert.DeserializeObject<CommonRequest>(content);

            if (request == null)
                return req.CreateResponse(HttpStatusCode.BadRequest);

            if (request.Id == Guid.Empty)
                return req.CreateResponse(HttpStatusCode.BadRequest);

            var data = await _appService.GetClientFranchises(request.Id.Value);

            var response = req.CreateResponse(HttpStatusCode.OK);

            await response.WriteAsJsonAsync(data);

            return response;
        }

<omitting screenshot image>

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,542 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,562 questions
{count} votes

Accepted answer
  1. Mike Urnun 9,781 Reputation points Microsoft Employee
    2024-01-06T03:56:27.4833333+00:00

    Hello @Muhammad Haseeb Rehman - I tested based on the same details you've shared in your post (except that mine didn't have the MealzNow types, of course) and think it's a minor config issue (not related to code), and as @Divakarkumar-3696 answered below, I also confirmed that the absence of "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated" setting can cause the error. Do you have any updates?

    Here's an official .NET 7 project sample with the correct configurations: https://github.com/Azure/azure-functions-dotnet-worker/tree/main/samples/Net7Worker

    BTW, support for .NET 7 is ending on May 14, 2024.

    4 people found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Divakarkumar-3696 375 Reputation points
    2024-01-03T05:36:30.9233333+00:00

    Hi @Muhammad Haseeb Rehman ,

    Please make sure in the local.settings.json file you have set worker runtime to Isolated, as below

    {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
    }
    

    If this is helpful please accept answer.

    3 people found this answer helpful.
    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Mercado, Marcos 0 Reputation points
    2024-06-14T21:00:36.76+00:00

    I was following this guide step by step, and kept getting this same error. After looking at the error trace, it looked like a key value/attribute name was not being recognized. All I did was change Anonymous to ANONYMOUS in my function_app.py file and it worked! Here are the first 10 lines of function_app.py:

    import azure.functions as func
    import datetime
    import json
    import logging
    app = func.FunctionApp()
    @app.route(route="HttpExample", auth_level=func.AuthLevel.ANONYMOUS)
    def HttpExample(req: func.HttpRequest) -> func.HttpResponse:
        logging.info('Python HTTP trigger function processed a request.')