【问题标题】:TimeTrigger Exception "Could not create BlobContainerClient for ScheduleMonitor."TimeTrigger 异常“无法为 ScheduleMonitor 创建 BlobContainerClient。”
【发布时间】:2022-01-27 01:08:07
【问题描述】:

当我使用 TimeTrigger 运行我的天蓝色函数时,出现以下错误: Microsoft.Azure.WebJobs.Extensions.Timers.Storage:无法为 ScheduleMonitor 创建 BlobContainerClient。

我使用主机生成器:

public static async Task Main()
        {
            var host = CreateHostBuilder().Build();

            using (host)
            {
                await host.RunAsync();
            }

        static IHostBuilder CreateHostBuilder() => new HostBuilder()
            .UseServiceProviderFactory(new AutofacServiceProviderFactory())
            .ConfigureFunctionsWorkerDefaults()
            .ConfigureHostConfiguration(configHost =>
            {
                configHost.SetBasePath(Directory.GetCurrentDirectory());
                configHost.AddJsonFile("host.json", optional: true);
                configHost.AddEnvironmentVariables();
            })
            .ConfigureAppConfiguration((hostContext, configApp) =>
            {
                var env = hostContext.HostingEnvironment;
                configApp.AddJsonFile("appsettings.json", optional: true);
                configApp.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
                configApp.AddEnvironmentVariables();
                configApp.AddApplicationInsightsSettings(developerMode: !env.IsProduction());
            })
            .ConfigureServices((hostContext, services) =>
            {
               [...]
            })
            .ConfigureContainer<ContainerBuilder>(builder =>
            {
                builder.RegisterModule<MessagerModule>();
            })
            .ConfigureLogging((hostContext, configLogging) =>
            {
                if (hostContext.HostingEnvironment.IsDevelopment())
                {
                    configLogging.AddConsole();
                    configLogging.AddDebug();
                }
            })
            .UseConsoleLifetime();

这里是函数:

[Function("QueueMessage")]
        public async Task QueueMessageAsync(
            [TimerTrigger("%MessageQueuerOccurence%", RunOnStartup = true)] TimerInfo timer
        )
        {
           [...]
        }

csproj:

<PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
        <OutputType>Exe</OutputType>
    </PropertyGroup>

    <ItemGroup>
        <Content Include="**\*.json" Exclude="bin\**\*;obj\**\*" CopyToOutputDirectory="Always" />
    </ItemGroup>
    
    <ItemGroup>
        <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
        <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="5.0.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.0" />
    </ItemGroup>

local.settings.json:

{ “IsEncrypted”:假, “价值观”:{ "AzureWebJobsStorage": "UseDevelopmentStorage=true", "MessageQueuerOccurence": "0 */15 * * * *", "FUNCTIONS_WORKER_RUNTIME": "dotnet 隔离" } }

我错过了什么?

注意:Github 链接:https://github.com/Azure/azure-functions-dotnet-worker/issues/779

【问题讨论】:

  • 您是在本地还是在 Azure 中部署后收到此错误?
  • 嗨,我在本地有这个错误。

标签: c# azure-functions


【解决方案1】:

我遇到这个问题是因为我没有运行存储模拟器...

一旦我安装并运行azurite,它就可以工作,这是正在维护的存储模拟器(Azure storage explorer 已停止使用)。您可以在here找到更多关于如何安装和使用它的信息。

我在 Mac OS 上使用 VS Code,我找到了在 VS Code 上安装 azurite 扩展的最简单的解决方案。安装后,我只需要编辑扩展设置,以设置location 设置(任何文件夹都可以使用)。之后,我可以通过从 VS Code 命令面板运行 Azurite: Start 来启动 azurite。

【讨论】:

  • 感谢您的建议 :) 存储模拟器已经在运行,我发现当我删除 appsettings.json 和 appsettings.Development.json 时,问题消失了。我在github上加了这个评论,因为是预览版,可能是配置不好...
  • 欢迎您!我没有在我的设置中使用任何这些文件,顺便说一句
  • 除此之外,我还必须编辑local.settings.json 文件并将AzureWebJobsStorage 值更改为UseDevelopmentStorage=true。 HTH :)
猜你喜欢
  • 2023-04-04
  • 2018-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-05
  • 2021-05-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多