【问题标题】:Functions on .net5: No job functions found. Try making your job classes and methods public.net5 上的功能:未找到工作功能。尝试公开您的工作类别和方法
【发布时间】:2021-09-19 00:20:35
【问题描述】:

我正在探索在 .net5 上运行函数应用程序。这是我目前所拥有的。

这是替换 Startup 类的新 Program 类:

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();
    }
}

我也有这个非常简单的 HTTP 触发函数:

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);
    }
}

我已修改我的local.settings.json 以表明该函数必须在隔离模式下运行:

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

我使用以下参数启动函数:

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

问题

当我启动应用程序时,我收到以下警告消息:

[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.).

我相信我在隔离进程中对.net5 运行函数时遵循了instructions。我错过了什么?

更新

这是版本信息:

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

【问题讨论】:

    标签: c# azure azure-functions .net-5


    【解决方案1】:

    我不是 100% 确定罪魁祸首是什么,但我现在可以正常工作了。我已将.Net 更新为最新的net5 SDK (5.0.301)。

    然后我意识到我的local.settings.json 文件缺少一些信息,我认为最重要的是FUNCTIONS_EXTENSION_VERSION 字段:

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

    这是输出:

    [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)
    

    更新

    我最终遇到了同样的问题,需要我添加 Microsoft.Azure.Functions.Worker.Sdk 包并更新 .csproj 文件以包含以下行:

    <OutputType>Exe</OutputType>
        
    

    【讨论】:

      猜你喜欢
      • 2018-05-20
      • 2017-09-11
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2017-11-13
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      相关资源
      最近更新 更多