Ced*_*uld 14 c# azure-functions
当我使用 TimeTrigger 运行我的 azure 函数时,出现以下错误: 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();
Run Code Online (Sandbox Code Playgroud)
这是函数:
[Function("QueueMessage")]
public async Task QueueMessageAsync(
[TimerTrigger("%MessageQueuerOccurence%", RunOnStartup = true)] TimerInfo timer
)
{
[...]
}
Run Code Online (Sandbox Code Playgroud)
项目:
<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>
Run Code Online (Sandbox Code Playgroud)
本地.settings.json:
{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "MessageQueuerOccurence": "0 */15 * * * *", "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated" } }
我错过了什么?
注意:Github 链接:https ://github.com/Azure/azure-functions-dotnet-worker/issues/779
rsy*_*rsy 32
我遇到这个问题是因为我没有运行存储模拟器......
一旦我安装并运行azurite
,它就可以工作,这是正在维护的存储模拟器(Azure Storage Emulator
已停止使用)。您可以在此处找到有关如何安装和使用它的更多信息。
我在 Mac OS 上使用 VS Code,我找到了在 VS Code 上安装azurite
扩展的最简单的解决方案。安装后,我只需编辑扩展设置,即可设置该location
设置(任何文件夹都可以)。之后,我可以从 VS Code 命令面板azurite
运行开始。Azurite: Start
根据评论,可能还需要编辑local.settings.json
文件并将AzureWebJobsStorage
值更改为UseDevelopmentStorage=true
.