函数“Function1”的侦听器无法启动

Nan*_*rya 1 azure-functions

在本地运行简单的计时器触发器 Azure 函数时,出现以下错误。

我使用 Visual Studio 2019 创建带有计时器触发器的新 Azure Functions 项目。

我安装了 Azure 开发工作负载。 已安装 Azure 开发工作负载

代码:

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp1
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([TimerTrigger("*/12 * * * * *")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

错误:

[2021-11-24T15:45:29.878Z] The listener for function 'Function1' was unable to start.
[2021-11-24T15:45:29.880Z] The listener for function 'Function1' was unable to start. Azure.Storage.Blobs: Server encountered an internal error. Please try again after some time.
RequestId:3bb00ada-83ec-4685-987b-5d4b51cb39db
Time:2021-11-24T15:45:29.5583585Z
[2021-11-24T15:45:29.880Z] Status: 500 (Server encountered an internal error. Please try again after some time.)
[2021-11-24T15:45:29.881Z] ErrorCode: InternalError
Run Code Online (Sandbox Code Playgroud)

此答案建议禁用防火墙。看来防火墙对我来说也是问题。当禁用防火墙不可行时,有什么办法可以克服这个问题吗?

小智 5

经过所有讨论后,很高兴您的问题得到解决。

这是我在本地环境中测试的帮助其他社区成员的解决方案:

下面是代码:

本地.settings.json

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}
Run Code Online (Sandbox Code Playgroud)

函数1.cs

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace KrishTimerTriggerNetCore31
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([TimerTrigger("*/12 * * * *")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

输出:

在此输入图像描述

当您使用计时器触发器模板在 Visual Studio 中创建 azure 函数项目时,默认情况下您的local.settings.json文件包含此值 "AzureWebJobsStorage": "UseDevelopmentStorage=true"

如果是UseDevelopmentStorageto none,那么会出现同样的错误:

在此输入图像描述

在安装 Visual Studio 时,请确保所有必需的应用程序均已安装并保持最新,以满足您的要求,例如 Azure Functions Core Tools 版本、Azure 存储模拟器(本地)、.Net Core 运行时版本和 SDK 以及扩展。