gpt4 book ai didi

azure - 错误: Cannot bind parameter 'executionContext' to type ExecutionContext

转载 作者:行者123 更新时间:2023-12-03 04:09:22 24 4
gpt4 key购买 nike

我有一个 .Net Framework 控制台应用程序,可以在 Azure 中成功将其发布为 WebJob 并查看它的运行情况。当我尝试向函数添加 ExecutionContext 参数时,我收到上述错误消息(无论参数的位置如何)。

我尝试将参数移动到方法签名中的每个位置。每次都出现同样的错误。

启动.cs

            var config = new JobHostConfiguration
{
JobActivator = new AuditorSyncActivator(serviceProvider)
};

// Setting the value of connection limit to that which the Sandbox would impose
// which should be sufficient for the application going forward, given demand.
ServicePointManager.DefaultConnectionLimit = 300;

// We are using an NCRONTAB expression to run the function on a schedule
config.UseTimers();
var host = new JobHost(config);

// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}

函数.cs


[FunctionName("AuditorSync")]
public void ProcessQueueMessage(
[TimerTrigger("0 */5 * * * *", RunOnStartup = false)] TimerInfo timer,
ExecutionContext executionContext,
Microsoft.Extensions.Logging.ILogger logger)
{
if (timer.IsPastDue)
{
_logger.Warning("Timer is running late");
}

_logger.Information($"WebJob Function Execution: Id={executionContext.InvocationId}, Action={_config.GetSection("AuditorSyncOptions")["Action"]}");
}

根据 Documentation,我预计它可以在 Azure 上运行,没问题。 。我在 Azure 的日志中得到的是

[08/27/2019 22:28:03 > e3a876: ERR ] Unhandled Exception: Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method 'Functions.ProcessQueueMessage' ---> System.InvalidOperationException: Cannot bind parameter 'executionContext' to type ExecutionContext. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

所有这些都没有详细记录,并且支持多个版本...我正在使用 WebJobs 的 2.x 版本...

欢迎任何想法:)

最佳答案

您可以通过调用config.UseCore()来注册它,之后您将能够使用ExecutionContext来检索有关当前正在运行的函数的信息。

更多信息,您可以引用此文档:Core Extensions 。以下是我的测试。

static void Main(string[] args)
{
var config = new JobHostConfiguration();
config.DashboardConnectionString = "connection";
config.UseTimers();
config.UseCore();


var host = new JobHost(config);
host.RunAndBlock();
}

enter image description here

关于azure - 错误: Cannot bind parameter 'executionContext' to type ExecutionContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57683137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com