我有一个Azure框架控制台应用程序,我可以在.Net中成功地将其作为WebJob发布,并看到它正在运行。当我试图向我的函数添加一个ExecutionContext参数时,我收到了上面的错误消息(与参数的位置无关)。
我已经尝试将参数移动到方法签名中的每个位置。每次都有相同的错误。
Startup.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();
}Functions.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.).所有这些都没有很好的文档记录,并且有几个版本被支持...我使用的是2.x版本的WebJobs...
欢迎任何想法:)
发布于 2019-08-28 12:07:34
您可以将其注册到调用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();
}

https://stackoverflow.com/questions/57683137
复制相似问题