Kzryzstof
Kzryzstof

Reputation: 8382

Functions on .net5: No job functions found. Try making your job classes and methods public

I am exploring running a Function App on .net5. Here is what I have so far.

Here is the new Program class which replaces the Startup class:

public static class Program
{
    private static Task Main(string[] args)
    {
        IHost host = new HostBuilder()
            .ConfigureAppConfiguration(configurationBuilder => { configurationBuilder.AddCommandLine(args); })
            .ConfigureFunctionsWorkerDefaults()
            .ConfigureServices(services =>
            {
                // Add Logging
                services.AddLogging();

                // Add HttpClient
                services.AddHttpClient();

                // Add Custom Services
            })
            .Build();

        return host.RunAsync();
    }
}

I also have this very simple HTTP Triggered Function:

public sealed class StorageAccountsFunction
{
    private readonly ILogger<StorageAccountsFunction> m_logger;

    public StorageAccountsFunction(ILogger<StorageAccountsFunction> logger)
    {
        m_logger = logger;
    }

    [Function("v1-get-storage-accounts")]
    public HttpResponseData GetAsync
    (
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "api/v1/storage-accounts")] 
        HttpRequestData httpRequestData, 
        FunctionContext context
    )
    {
        return httpRequestData.CreateResponse(System.Net.HttpStatusCode.OK);
    }
}

I have modified my local.settings.json to indicate that the Function must run in the isolated mode:

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

I start the Function with the following parameters:

func host start --pause-on-error --verbose --dotnet-isolated-debug

Question

When I start the app, I get this warning message:

[2021-07-08T13:13:54.813Z] Loading functions metadata
[2021-07-08T13:13:54.814Z] Reading functions metadata
[2021-07-08T13:13:54.815Z] 0 functions found
[2021-07-08T13:13:54.841Z] 0 functions loaded
[2021-07-08T13:13:54.868Z] Generating 0 job function(s)
[2021-07-08T13:13:54.898Z] 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.).

I believe I have followed the instructions when running a Function on .net5 in isolated process. What am I missing?

Update

Here is the versions information:

Core Tools Version:       3.0.3568 Commit hash: e30a0ede85fd498199c28ad699ab2548593f759b  (64-bit)
Function Runtime Version: 3.0.15828.0

Upvotes: 1

Views: 3868

Answers (1)

Kzryzstof
Kzryzstof

Reputation: 8382

I am not 100% sure what was the culprit but I got it working now. I have updated .Net to the latest net5 SDK (5.0.301).

Then I realized that my local.settings.json file was missing few information, most importantly I believe is the FUNCTIONS_EXTENSION_VERSION field:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
        "FUNCTIONS_EXTENSION_VERSION": "~3"
    },
    "Host": {
        "LocalHttpPort": 7072,
        "CORS": "*"
    }
}

Here is output:

[2021-07-10T12:53:30.478Z] EnvironmentVariable FUNCTIONS_WORKER_RUNTIME: dotnet-isolated
[2021-07-10T12:53:30.478Z] EnvironmentVariable FUNCTIONS_WORKER_RUNTIME_VERSION: 
[2021-07-10T12:53:30.478Z] Added WorkerConfig for language: dotnet-isolated
[2021-07-10T12:53:30.479Z] Reading functions metadata
[2021-07-10T12:53:30.480Z] 0 functions found
[2021-07-10T12:53:30.489Z] 1 functions loaded
[2021-07-10T12:53:30.506Z] Adding Function descriptor provider for language dotnet-isolated.
[2021-07-10T12:53:30.508Z] Creating function descriptors.
[2021-07-10T12:53:30.563Z] Function descriptors created.
[2021-07-10T12:53:30.572Z] Generating 1 job function(s)

Update

I ended up with the same problem which required me to add the Microsoft.Azure.Functions.Worker.Sdk package and update the .csproj file to include the following line:

<OutputType>Exe</OutputType>
    

Upvotes: 3

Related Questions